Class: DRb::ThreadObject

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/drb/drb.rb

Instance Method Summary collapse

Constructor Details

#initialize(&blk) ⇒ ThreadObject

Returns a new instance of ThreadObject.



1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
# File 'lib/drb/drb.rb', line 1201

def initialize(&blk)
  super()
  @wait_ev = new_cond
  @req_ev = new_cond
  @res_ev = new_cond
  @status = :wait
  @req = nil
  @res = nil
  @thread = Thread.new(self, &blk)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *arg, &blk) ⇒ Object



1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
# File 'lib/drb/drb.rb', line 1221

def method_missing(msg, *arg, &blk)
  synchronize do
    @wait_ev.wait_until { @status == :wait }
    @req = [msg] + arg
    @status = :req
    @req_ev.broadcast
    @res_ev.wait_until { @status == :res }
    value = @res
    @req = @res = nil
    @status = :wait
    @wait_ev.broadcast
    return value
  end
end

Instance Method Details

#_executeObject



1236
1237
1238
1239
1240
1241
1242
1243
# File 'lib/drb/drb.rb', line 1236

def _execute()
  synchronize do
    @req_ev.wait_until { @status == :req }
    @res = yield(@req)
    @status = :res
    @res_ev.signal
  end
end

#alive?Boolean

Returns:

  • (Boolean)


1212
1213
1214
# File 'lib/drb/drb.rb', line 1212

def alive?
  @thread.alive?
end

#killObject



1216
1217
1218
1219
# File 'lib/drb/drb.rb', line 1216

def kill
  @thread.kill
  @thread.join
end