| Coro documentation | Contained in the Coro distribution. |
Coro::Signal - thread signals (binary semaphores)
use Coro; $sig = new Coro::Signal; $sig->wait; # wait for signal # ... some other "thread" $sig->send;
This module implements signals/binary semaphores/condition variables (basically all the same thing). You can wait for a signal to occur or send it, in which case it will wake up one waiter, or it can be broadcast, waking up all waiters.
It is recommended not to mix send and broadcast calls on the same
Coro::Signal - it should work as documented, but it can easily confuse
you :->
You don't have to load Coro::Signal manually, it will be loaded
automatically when you use Coro and call the new constructor.
Create a new signal.
Wait for the signal to occur (via either send or broadcast). Returns
immediately if the signal has been sent before.
If you pass a callback argument to wait, it will not wait, but
immediately return. The callback will be called under the same conditions
as wait without arguments would continue the thrad.
The callback might wake up any number of threads, but is NOT allowed to block (switch to other threads).
Send the signal, waking up one waiting process or remember the signal if no process is waiting.
Send the signal, waking up all waiting process. If no process is waiting the signal is lost.
Return true when the signal is being awaited by some process.
Marc Lehmann <schmorp@schmorp.de> http://home.schmorp.de/
| Coro documentation | Contained in the Coro distribution. |
package Coro::Signal; use common::sense; use Coro::Semaphore (); our $VERSION = 6.0;
#=item $status = $s->timed_wait ($timeout) # #Like C<wait>, but returns false if no signal happens within $timeout #seconds, otherwise true. # #See C<wait> for some reliability concerns. # #=cut #ub timed_wait { # require Coro::Timer; # my $timeout = Coro::Timer::timeout($_[1]); # # unless (delete $_[0][0]) { # push @{$_[0][1]}, $Coro::current; # &Coro::schedule; # # return 0 if $timeout; # } # # 1 # 1;