1SemaphoreSet(3)       User Contributed Perl Documentation      SemaphoreSet(3)
2
3
4

NAME

6       Coro::SemaphoreSet - efficient set of counting semaphores
7

SYNOPSIS

9        use Coro;
10
11        $sig = new Coro::SemaphoreSet [initial value];
12
13        $sig->down ("semaphoreid"); # wait for signal
14
15        # ... some other "thread"
16
17        $sig->up ("semaphoreid");
18

DESCRIPTION

20       This module implements sets of counting semaphores (see
21       Coro::Semaphore). It is nothing more than a hash with normal semaphores
22       as members, but is more efficiently managed.
23
24       This is useful if you want to allow parallel tasks to run in parallel
25       but not on the same problem. Just use a SemaphoreSet and lock on the
26       problem identifier.
27
28       You don't have to load "Coro::SemaphoreSet" manually, it will be loaded
29       automatically when you "use Coro" and call the "new" constructor.
30
31       new [initial count]
32           Creates a new semaphore set with the given initial lock count for
33           each individual semaphore. See Coro::Semaphore.
34
35       $semset->down ($id)
36           Decrement the counter, therefore "locking" the named semaphore.
37           This method waits until the semaphore is available if the counter
38           is zero.
39
40       $semset->up ($id)
41           Unlock the semaphore again. If the semaphore reaches the default
42           count for this set and has no waiters, the space allocated for it
43           will be freed.
44
45       $semset->try ($id)
46           Try to "down" the semaphore. Returns true when this was possible,
47           otherwise return false and leave the semaphore unchanged.
48
49       $semset->count ($id)
50           Return the current semaphore count for the specified semaphore.
51
52       $semset->waiters ($id)
53           Returns the number (in scalar context) or list (in list context) of
54           waiters waiting on the specified semaphore.
55
56       $semset->wait ($id)
57           Same as Coro::Semaphore::wait on the specified semaphore.
58
59       $guard = $semset->guard ($id)
60           This method calls "down" and then creates a guard object. When the
61           guard object is destroyed it automatically calls "up".
62
63       $semaphore = $semset->sem ($id)
64           This SemaphoreSet version is based on Coro::Semaphore's. This
65           function creates (if necessary) the underlying Coro::Semaphore
66           object and returns it. You may legally call any Coro::Semaphore
67           method on it, but note that calling "$semset->up" can invalidate
68           the returned semaphore.
69

AUTHOR/SUPPORT/CONTACT

71          Marc A. Lehmann <schmorp@schmorp.de>
72          http://software.schmorp.de/pkg/Coro.html
73
74
75
76perl v5.30.0                      2019-07-26                   SemaphoreSet(3)
Impressum