… | |
… | |
2 | |
2 | |
3 | Coro::Semaphore - counting semaphores |
3 | Coro::Semaphore - counting semaphores |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use Coro::Semaphore; |
7 | use Coro; |
8 | |
8 | |
9 | $sig = new Coro::Semaphore [initial value]; |
9 | $sig = new Coro::Semaphore [initial value]; |
10 | |
10 | |
11 | $sig->down; # wait for signal |
11 | $sig->down; # wait for signal |
12 | |
12 | |
… | |
… | |
25 | Counting semaphores are typically used to coordinate access to |
25 | Counting semaphores are typically used to coordinate access to |
26 | resources, with the semaphore count initialized to the number of free |
26 | resources, with the semaphore count initialized to the number of free |
27 | resources. Threads then increment the count when resources are added |
27 | resources. Threads then increment the count when resources are added |
28 | and decrement the count when resources are removed. |
28 | and decrement the count when resources are removed. |
29 | |
29 | |
|
|
30 | You don't have to load C<Coro::Semaphore> manually, it will be loaded |
|
|
31 | automatically when you C<use Coro> and call the C<new> constructor. |
|
|
32 | |
30 | =over 4 |
33 | =over 4 |
31 | |
34 | |
32 | =cut |
35 | =cut |
33 | |
36 | |
34 | package Coro::Semaphore; |
37 | package Coro::Semaphore; |
35 | |
38 | |
36 | use common::sense; |
39 | use common::sense; |
37 | |
40 | |
38 | use Coro (); |
41 | use Coro (); |
39 | |
42 | |
40 | our $VERSION = 5.24; |
43 | our $VERSION = 5.37; |
41 | |
44 | |
42 | =item new [inital count] |
45 | =item new [inital count] |
43 | |
46 | |
44 | Creates a new sempahore object with the given initial lock count. The |
47 | Creates a new sempahore object with the given initial lock count. The |
45 | default lock count is 1, which means it is unlocked by default. Zero (or |
48 | default lock count is 1, which means it is unlocked by default. Zero (or |