… | |
… | |
4 | # one process produces items, send s a signal. |
4 | # one process produces items, send s a signal. |
5 | # another process waits for that signal and |
5 | # another process waits for that signal and |
6 | # consumed the item. |
6 | # consumed the item. |
7 | |
7 | |
8 | use Coro; |
8 | use Coro; |
9 | use Coro::Process; |
|
|
10 | use Coro::Semaphore; |
9 | use Coro::Semaphore; |
11 | |
10 | |
12 | my $produced = new Coro::Semaphore; |
11 | my $produced = new Coro::Semaphore 0; |
13 | my $finished = new Coro::Semaphore 0; |
12 | my $finished = new Coro::Semaphore 0; |
14 | |
13 | |
15 | async { |
14 | async { |
16 | for my $i (0..9) { |
15 | for my $i (0..9) { |
17 | print "produced $i\n"; |
16 | print "produced $i\n"; |
… | |
… | |
19 | $produced->up; |
18 | $produced->up; |
20 | yield if @buffer > 5; # simulate memory pressure ;) |
19 | yield if @buffer > 5; # simulate memory pressure ;) |
21 | } |
20 | } |
22 | print "work done\n"; |
21 | print "work done\n"; |
23 | $finished->up; |
22 | $finished->up; |
24 | $idle; |
|
|
25 | }; |
23 | }; |
26 | |
24 | |
27 | async { |
25 | async { |
28 | while () { |
26 | while () { |
29 | $produced->down; |
27 | $produced->down; |