1 | #!/usr/bin/perl |
1 | #!/usr/bin/perl |
2 | |
2 | |
3 | # the classical producer/consumer example, using semaphores |
3 | # the classical producer/consumer example, using a channel |
4 | # one process produces items, send s a signal. |
4 | # one process produces items, sends 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::Channel; |
9 | use Coro::Channel; |
11 | use Coro::Signal; |
10 | use Coro::Signal; |
12 | |
11 | |
13 | my $work = new Coro::Channel 3; |
12 | my $work = new Coro::Channel 3; |
14 | my $finished = new Coro::Signal; |
13 | my $finished = new Coro::Signal; |
… | |
… | |
31 | |
30 | |
32 | $finished->wait; |
31 | $finished->wait; |
33 | |
32 | |
34 | print "producer finished\n"; |
33 | print "producer finished\n"; |
35 | |
34 | |
36 | yield while $work->size; |
35 | cede while $work->size; |
37 | |
36 | |
38 | print "job finished\n"; |
37 | print "job finished\n"; |
39 | |
38 | |