Class: DRb::ThreadObject
- Inherits:
-
Object
show all
- Includes:
- MonitorMixin
- Defined in:
- lib/drb/drb.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ThreadObject.
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
|
# File 'lib/drb/drb.rb', line 1230
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
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
|
# File 'lib/drb/drb.rb', line 1250
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
#_execute ⇒ Object
1265
1266
1267
1268
1269
1270
1271
1272
|
# File 'lib/drb/drb.rb', line 1265
def _execute()
synchronize do
@req_ev.wait_until { @status == :req }
@res = yield(@req)
@status = :res
@res_ev.signal
end
end
|
#alive? ⇒ Boolean
1241
1242
1243
|
# File 'lib/drb/drb.rb', line 1241
def alive?
@thread.alive?
end
|
#kill ⇒ Object
1245
1246
1247
1248
|
# File 'lib/drb/drb.rb', line 1245
def kill
@thread.kill
@thread.join
end
|