class Celluloid::Internals::ThreadHandle
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
Public Class Methods
new(actor_system, role = nil) { || ... }
click to toggle source
# File lib/celluloid/internals/thread_handle.rb, line 7 def initialize(actor_system, role = nil) @mutex = Mutex.new @join = ConditionVariable.new @thread = actor_system.get_thread do Thread.current.role = role begin yield ensure @mutex.synchronize do @thread = nil @join.broadcast end end end end
Public Instance Methods
alive?()
click to toggle source
Is the thread running?
# File lib/celluloid/internals/thread_handle.rb, line 25 def alive? @mutex.synchronize { @thread.alive? if @thread } end
backtrace()
click to toggle source
Obtain the backtrace for this thread
# File lib/celluloid/internals/thread_handle.rb, line 43 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(limit = nil)
click to toggle source
Join to a running thread, blocking until it terminates
# File lib/celluloid/internals/thread_handle.rb, line 36 def join(limit = nil) fail ThreadError, "Target thread must not be current thread" if @thread == Thread.current @mutex.synchronize { @join.wait(@mutex, limit) if @thread } self end
kill()
click to toggle source
Forcibly kill the thread
# File lib/celluloid/internals/thread_handle.rb, line 30 def kill !!@mutex.synchronize { @thread.kill if @thread } self end