Parent

Class/Module Index [+]

Quicksearch

Celluloid::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(role = nil) click to toggle source
# 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

Public Instance Methods

alive?() click to toggle source

Is the thread running?

# File lib/celluloid/thread_handle.rb, line 24
def alive?
  @mutex.synchronize { @thread.alive? if @thread }
end
backtrace() click to toggle source

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(limit = nil) click to toggle source

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
kill() click to toggle source

Forcibly kill the thread

# File lib/celluloid/thread_handle.rb, line 29
def kill
  !!@mutex.synchronize { @thread.kill if @thread }
  self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.