Coro::SemaphoreSet - efficient set of counting semaphores
$sig = new Coro::SemaphoreSet [initial value];
$sig->down ("semaphoreid"); # wait for signal
# ... some other "thread"
This module implements sets of counting semaphores (see Coro::Semaphore). 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.
You don't have to load Coro::SemaphoreSet manually, it will be loaded automatically when you use Coro and call the new constructor.
Creates a new semaphore set with the given initial lock count for each individual semaphore. See Coro::Semaphore.
Decrement the counter, therefore "locking" the named semaphore. This method waits until the semaphore is available if the counter is zero.
Unlock the semaphore again. If the semaphore reaches the default count for this set and has no waiters, the space allocated for it will be freed.
Try to down the semaphore. Returns true when this was possible, otherwise return false and leave the semaphore unchanged.
Return the current semaphore count for the specified semaphore.
Returns the number (in scalar context) or list (in list context) of waiters waiting on the specified semaphore.
Same as Coro::Semaphore::wait on the specified semaphore.
This method calls down and then creates a guard object. When the guard object is destroyed it automatically calls up.
This SemaphoreSet version is based on Coro::Semaphore's. This function creates (if necessary) the underlying Coro::Semaphore object and returns it. You may legally call any Coro::Semaphore method on it, but note that calling $semset->up can invalidate the returned semaphore.
Marc A. Lehmann <firstname.lastname@example.org>
To install Coro, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.