|
Coro::Semaphore - non-binary semaphores |
Coro::Semaphore - non-binary semaphores
use Coro::Semaphore;
$sig = new Coro::Semaphore [initial value];
$sig->down; # wait for signal
# ... some other "thread"
$sig->up;
This module implements counting semaphores. You can initialize a mutex
with any level of parallel users, that is, you can intialize a sempahore
that can be downed more than once until it blocks. There is no owner
associated with semaphores, so one coroutine can down it while another
can up it.
Counting semaphores are typically used to coordinate access to resources, with the semaphore count initialized to the number of free resources. Coroutines then increment the count when resources are added and decrement the count when resources are removed.
timed_down($timeout)down, but returns false if semaphore couldn't be acquired within
$timeout seconds, otherwise true.
down the semaphore. Returns true when this was possible,
otherwise return false and leave the semaphore unchanged.
down and then creates a guard object. When the guard
object is destroyed it automatically calls up.
timed_guard($timeout)guard, but returns undef if semaphore couldn't be acquired within
$timeout seconds, otherwise the guard object.
Marc Lehmann <pcg@goof.com> http://www.goof.com/pcg/marc/
|
Coro::Semaphore - non-binary semaphores |