NAME

Coro::Signal - coroutine 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 signal/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.

$s = new Coro::Signal;

Create a new signal.

$s->wait

Wait for the signal to occur. Returns immediately if the signal has been sent before.

Signals are not reliable: this function might return spuriously without the signal being sent. This means you must always test for the condition you are waiting for.

(If this is a real problem for you the situation might be remedied in a future version).

$status = $s->timed_wait ($timeout)

Like wait, but returns false if no signal happens within $timeout seconds, otherwise true.

See wait for some reliability concerns.

$s->send

Send the signal, waking up one waiting process or remember the signal if no process is waiting.

$s->broadcast

Send the signal, waking up all waiting process. If no process is waiting the signal is lost.

$s->awaited

Return true when the signal is being awaited by some process.

BUGS

This implementation is not currently very robust when the process is woken up by other sources, i.e. wait might return early.

AUTHOR

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