Coro::Signal.3pm

Langue: en

Autres versions - même langue

Version: 2010-05-17 (ubuntu - 24/10/10)

Section: 3 (Bibliothèques de fonctions)

NAME

Coro::Signal - thread signals (binary semaphores)

SYNOPSIS

  use Coro::Signal;
 
  $sig = new Coro::Signal;
 
  $sig->wait; # wait for signal
 
  # ... some other "thread"
 
  $sig->send;
 
 

DESCRIPTION

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 :->

$sig = new Coro::Signal;
Create a new signal.
$sig->wait
Wait for the signal to occur (via either "send" or "broadcast"). Returns immediately if the signal has been sent before.
$sem->wait ($callback)
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).

$sig->send
Send the signal, waking up one waiting process or remember the signal if no process is waiting.
$sig->broadcast
Send the signal, waking up all waiting process. If no process is waiting the signal is lost.
$sig->awaited
Return true when the signal is being awaited by some process.

AUTHOR

  Marc Lehmann <schmorp@schmorp.de>
  http://home.schmorp.de/