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.



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

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



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

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



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

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

#alive?Boolean

Returns:

  • (Boolean)


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

def alive?
  @thread.alive?
end

#killObject



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

def kill
  @thread.kill
  @thread.join
end