Object
An abstraction around threads from the InternalPool which ensures we don't accidentally do things to threads which have been returned to the pool, such as, say, killing them
# File lib/celluloid/thread_handle.rb, line 6 def initialize(role = nil) @mutex = Mutex.new @join = ConditionVariable.new @thread = Celluloid.internal_pool.get do Thread.current.role = role begin yield ensure @mutex.synchronize do @thread = nil @join.broadcast end end end end
Is the thread running?
# File lib/celluloid/thread_handle.rb, line 24 def alive? @mutex.synchronize { @thread.alive? if @thread } end
Obtain the backtrace for this thread
# File lib/celluloid/thread_handle.rb, line 42 def backtrace @thread.backtrace rescue NoMethodError # undefined method `backtrace' for nil:NilClass # Swallow this in case this ThreadHandle was terminated and @thread was # set to nil end
Join to a running thread, blocking until it terminates
# File lib/celluloid/thread_handle.rb, line 35 def join(limit = nil) raise ThreadError, "Target thread must not be current thread" if @thread == Thread.current @mutex.synchronize { @join.wait(@mutex, limit) if @thread } self end
Generated with the Darkfish Rdoc Generator 2.