module LightIO::Module::Thread::ClassMethods

Public Instance Methods

current() click to toggle source
# File lib/lightio/module/thread.rb, line 32
def current
  return main if LightIO::Core::LightFiber.is_root?(Fiber.current)
  LightIO::Library::Thread.instance_variable_get(:@current_thread) || origin_current
end
exclusive(&blk) click to toggle source
# File lib/lightio/module/thread.rb, line 37
def exclusive(&blk)
  LightIO::Library::Thread.__send__(:thread_mutex).synchronize(&blk)
end
finalizer(object_id) click to toggle source
# File lib/lightio/module/thread.rb, line 67
def finalizer(object_id)
  proc {LightIO::Library::Thread.__send__(:threads).delete(object_id)}
end
fork(*args, &blk) click to toggle source
# File lib/lightio/module/thread.rb, line 20
def fork(*args, &blk)
  obj = LightIO::Library::Thread.__send__ :allocate
  obj.send(:init_core, *args, &blk)
  obj
end
Also aliased as: start
kill(thr) click to toggle source
# File lib/lightio/module/thread.rb, line 28
def kill(thr)
  thr.kill
end
list() click to toggle source
# File lib/lightio/module/thread.rb, line 41
def list
  thread_list = []
  LightIO::Library::Thread.__send__(:threads).keys.each {|id|
    begin
      thr = ObjectSpace._id2ref(id)
      unless thr.alive?
        # manually remove thr from threads
        thr.kill
        next
      end
      thread_list << thr
    rescue RangeError
      # mean object is recycled
      # just wait ruby GC call finalizer to remove it from threads
      next
    end
  }
  thread_list
end
main() click to toggle source
# File lib/lightio/module/thread.rb, line 71
def main
  origin_main
end
new(*args, &blk) click to toggle source
# File lib/lightio/module/thread.rb, line 14
def new(*args, &blk)
  obj = LightIO::Library::Thread.__send__ :allocate
  obj.__send__ :initialize, *args, &blk
  obj
end
pass() click to toggle source
# File lib/lightio/module/thread.rb, line 61
def pass
  LightIO::Beam.pass
end
Also aliased as: stop
start(*args, &blk)
Alias for: fork
stop()
Alias for: pass