Class: Concurrent::Selectable::Latch
- Defined in:
- lib/concurrent/selectable/latch.rb
Overview
A latch is a toggle which starts out unset. Threads can wait for the latch to become set by calling Latch#wait (inherited from Base). The latch can be reset to its intial state using Latch#reset.
Instance Method Summary collapse
-
#initialize ⇒ Latch
constructor
A new instance of Latch.
-
#reset ⇒ Object
Resets the latch, blocking any subsequent waiting threads until the latch is set again.
-
#set ⇒ Object
Sets the latch, allowing any current and future waiting threads to continue.
-
#set? ⇒ Boolean
Non-blocking test whether the latch is currently set (additional external synchronization will usually be required if the latch can be set or reset by other threads).
Methods inherited from Base
Constructor Details
#initialize ⇒ Latch
Returns a new instance of Latch.
45 46 47 48 49 |
# File 'lib/concurrent/selectable/latch.rb', line 45 def initialize super() @lock = ::Mutex.new @set = false end |
Instance Method Details
#reset ⇒ Object
Resets the latch, blocking any subsequent waiting threads until the latch is set again
70 71 72 73 74 75 76 |
# File 'lib/concurrent/selectable/latch.rb', line 70 def reset @lock.synchronize do internal_reset if @set @set = false end self end |
#set ⇒ Object
Sets the latch, allowing any current and future waiting threads to continue
53 54 55 56 57 58 59 |
# File 'lib/concurrent/selectable/latch.rb', line 53 def set @lock.synchronize do internal_set unless @set @set = true end self end |
#set? ⇒ Boolean
Non-blocking test whether the latch is currently set (additional external synchronization will usually be required if the latch can be set or reset by other threads)
64 65 66 |
# File 'lib/concurrent/selectable/latch.rb', line 64 def set? @lock.synchronize { @set } end |