class Concurrent::Event
# event occurred
# t2 calling set
# t1 is waiting
# prints:
[t1, t2].each(&:join)
end
event.set
puts “t2 calling set”
t2 = Thread.new do
end
puts “event occurred”
event.wait(1)
puts “t1 is waiting”
t1 = Thread.new do
event = Concurrent::Event.new
@example
@see msdn.microsoft.com/en-us/library/windows/desktop/ms682655.aspx<br><br>‘#reset` at any time once it has been set.
New threads calling `#wait` will return immediately. An `Event` may be
will then wake up all listeners. Once an `Event` has been set it remains set.
thread wants to alert all blocking threads it calls the `#set` method which
`#wait` on the event, blocking until released by another thread. When one
When an `Event` is created it is in the `unset` state. Threads can choose to
Old school kernel-style event reminiscent of Win32 programming in C++.
def initialize
Creates a new `Event` in the unset state. Threads calling `#wait` on the
def initialize super synchronize { ns_initialize } end
def ns_initialize
def ns_initialize @set = false @iteration = 0 end
def ns_set
def ns_set unless @set @set = true ns_broadcast end true end
def reset
-
(Boolean)
- should always return `true`
def reset synchronize do if @set @set = false @iteration +=1 end true end end
def set
-
(Boolean)
- should always return `true`
def set synchronize { ns_set } end
def set?
-
(Boolean)
- indicating whether or not the `Event` has been set
def set? synchronize { @set } end
def try?
def try? synchronize { @set ? false : ns_set } end
def wait(timeout = nil)
-
(Boolean)
- true if the `Event` was set before timeout else false
def wait(timeout = nil) synchronize do unless @set iteration = @iteration ns_wait_until(timeout) { iteration < @iteration || @set } else true end end end