Coro::SemaphoreSet - hash of semaphores. |
Coro::SemaphoreSet - hash of semaphores.
use Coro::SemaphoreSet;
$sig = new Coro::SemaphoreSet [initial value];
$sig->down("semaphoreid"); # wait for signal
# ... some other "thread"
$sig->up("semaphoreid");
This module implements sets of counting semaphores (see the Coro::Semaphore manpage). It is nothing more than a hash with normal semaphores as members, but is more efficiently managed.
This is useful if you want to allow parallel tasks to run in parallel but not on the same problem. Just use a SemaphoreSet and lock on the problem identifier.
down($id)
down
, but returns false if semaphore couldn't be acquired within
$timeout seconds, otherwise true.
up($id)
down
the semaphore. Returns true when this was possible,
otherwise return false and leave the semaphore unchanged.
waiters($id)
guard($id)
down
and then creates a guard object. When the guard
object is destroyed it automatically calls up
.
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::SemaphoreSet - hash of semaphores. |