Class: LightIO::Library::Thread

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Base::MockMethods, Module::Thread::ClassMethods
Defined in:
lib/lightio/library/thread.rb

Defined Under Namespace

Classes: ConditionVariable, Mutex

Constant Summary collapse

ThreadError =

constants

::ThreadError
Queue =
LightIO::Library::Queue
Backtrace =
::Thread::Backtrace
SizedQueue =
LightIO::Library::SizedQueue

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Module::Thread::ClassMethods

current, exclusive, finalizer, fork, list, main, new, pass

Constructor Details

#initialize(*args, &blk) ⇒ Thread

Returns a new instance of Thread.



48
49
50
# File 'lib/lightio/library/thread.rb', line 48

def initialize(*args, &blk)
  init_core(*args, &blk)
end

Class Method Details

.method_missing(*args) ⇒ Object



203
204
205
# File 'lib/lightio/library/thread.rb', line 203

def method_missing(*args)
  ::Thread.__send__(*args)
end

.respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/lightio/library/thread.rb', line 207

def respond_to?(*args)
  ::Thread.respond_to?(*args)
end

.respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


211
212
213
# File 'lib/lightio/library/thread.rb', line 211

def respond_to_missing?(method, *)
  ::Thread.respond_to?(method)
end

Instance Method Details

#[](name) ⇒ Object



98
99
100
# File 'lib/lightio/library/thread.rb', line 98

def [](name)
  fiber_values[name.to_sym]
end

#[]=(name, val) ⇒ Object



102
103
104
# File 'lib/lightio/library/thread.rb', line 102

def []=(name, val)
  fiber_values[name.to_sym] = val
end

#groupObject



106
107
108
# File 'lib/lightio/library/thread.rb', line 106

def group
  @group
end

#inspectObject



110
111
112
# File 'lib/lightio/library/thread.rb', line 110

def inspect
  "#<LightIO::Library::Thread:0x00#{object_id.to_s(16)} #{status}>"
end

#join(limit = nil) ⇒ Object



114
115
116
# File 'lib/lightio/library/thread.rb', line 114

def join(limit=nil)
  @beam.join(limit) && self
end

#key?(sym) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/lightio/library/thread.rb', line 118

def key?(sym)
  fiber_values.has_key?(sym)
end

#keysObject



122
123
124
# File 'lib/lightio/library/thread.rb', line 122

def keys
  fiber_values.keys
end

#killObject Also known as: exit, terminate



65
66
67
# File 'lib/lightio/library/thread.rb', line 65

def kill
  @beam.kill && self
end

#raise(exception, message = nil, backtrace = nil) ⇒ Object



126
127
128
# File 'lib/lightio/library/thread.rb', line 126

def raise(exception, message=nil, backtrace=nil)
  @beam.raise(LightIO::Beam::BeamError.new(exception), message, backtrace)
end

#runObject Also known as: wakeup



130
131
132
133
# File 'lib/lightio/library/thread.rb', line 130

def run
  Kernel.raise ThreadError, 'killed thread' unless alive?
  Thread.pass
end

#statusObject



72
73
74
75
76
77
78
79
80
# File 'lib/lightio/library/thread.rb', line 72

def status
  if self.class.current == self
    'run'
  elsif alive?
    @beam.error.nil? ? 'sleep' : 'abouting'
  else
    @beam.error.nil? ? false : nil
  end
end

#stop?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/lightio/library/thread.rb', line 137

def stop?
  !alive? || status == 'sleep'
end

#thread_variable?(key) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/lightio/library/thread.rb', line 94

def thread_variable?(key)
  thread_values.key?(key)
end

#thread_variable_get(name) ⇒ Object



86
87
88
# File 'lib/lightio/library/thread.rb', line 86

def thread_variable_get(name)
  thread_values[name.to_sym]
end

#thread_variable_set(name, value) ⇒ Object



90
91
92
# File 'lib/lightio/library/thread.rb', line 90

def thread_variable_set(name, value)
  thread_values[name.to_sym] = value
end

#thread_variablesObject



82
83
84
# File 'lib/lightio/library/thread.rb', line 82

def thread_variables
  thread_values.keys
end