Module: Pione::Util::FreeThreadGenerator

Defined in:
lib/pione/util/free-thread-generator.rb

Overview

FreeThreadGenerator provides the function that creates new threads under main thread group. This is useful for escaping threadgroup encloser.

Class Method Summary collapse

Class Method Details

.generate(&b) ⇒ Object

Generate a thread with the block under default thread group.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pione/util/free-thread-generator.rb', line 14

def self.generate(&b)
  @method_lock.synchronize do
    @mutex.synchronize do
      @queue.push(b)
      @cv_response.wait(@mutex)
      thread = @__generated__
      @__generated__ = nil
      @cv_bye.signal
      return thread
    end
  end
end