Class: Celluloid::Internals::ThreadHandle

### Home Classes Methods

### In Files

- lib/celluloid/internals/thread_handle.rb

### Parent

Object

### Methods

- ::new
- #alive?
- #backtrace
- #join
- #kill

### Class/Module Index

Quicksearch

- Celluloid
- Celluloid::Incident
- Celluloid::IncidentLogger
- Celluloid::IncidentLogger::Severity
- Celluloid::IncidentReporter
- Celluloid::IncidentReporter::Formatter
- Celluloid::Internals
- Celluloid::Internals::CPUCounter
- Celluloid::Internals::CallChain
- Celluloid::Internals::Handler
- Celluloid::Internals::Handlers
- Celluloid::Internals::Links
- Celluloid::Internals::Logger
- Celluloid::Internals::Logger::WithBacktrace
- Celluloid::Internals::Method
- Celluloid::Internals::Properties
- Celluloid::Internals::Receiver
- Celluloid::Internals::Receivers
- Celluloid::Internals::Registry
- Celluloid::Internals::Response
- Celluloid::Internals::Response::Block
- Celluloid::Internals::Response::Error
- Celluloid::Internals::Response::Success
- Celluloid::Internals::Signals
- Celluloid::Internals::Stack
- Celluloid::Internals::Stack::ActorState
- Celluloid::Internals::Stack::CellState
- Celluloid::Internals::Stack::DisplayBacktrace
- Celluloid::Internals::Stack::Dump
- Celluloid::Internals::Stack::Summary
- Celluloid::Internals::Stack::TaskState
- Celluloid::Internals::Stack::ThreadState
- Celluloid::Internals::TaskSet
- Celluloid::Internals::ThreadHandle
- Celluloid::Internals::UUID
- Celluloid::LogEvent
- Celluloid::Notifications
- Celluloid::Notifications::Fanout
- Celluloid::Notifications::Subscriber
- Celluloid::Probe
- Celluloid::RingBuffer

No matching classes.

# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.