Class: ExecJS::PCRuntime::Semaphore
- Inherits:
-
Object
- Object
- ExecJS::PCRuntime::Semaphore
- Defined in:
- lib/execjs/pcruntime/context_process_runtime.rb
Overview
Semaphore implemented with Thread::Queue since faster than Concurrent::Semaphore and Mutex+ConditionVariable
Instance Method Summary collapse
-
#acquire ⇒ Object
acquires 1 of permits from this semaphore, blocking until be available.
-
#initialize(limit) ⇒ Semaphore
constructor
A new instance of Semaphore.
-
#release ⇒ Object
releases 1 of permits.
Constructor Details
#initialize(limit) ⇒ Semaphore
Returns a new instance of Semaphore.
315 316 317 318 |
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 315 def initialize(limit) @queue = Thread::Queue.new limit.times { @queue.push nil } end |
Instance Method Details
#acquire ⇒ Object
acquires 1 of permits from this semaphore, blocking until be available.
321 322 323 |
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 321 def acquire @queue.pop end |
#release ⇒ Object
releases 1 of permits
326 327 328 |
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 326 def release @queue.push nil end |