ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/prodcons2
(Generate patch)

Comparing Coro/eg/prodcons2 (file contents):
Revision 1.3 by root, Tue Jul 10 01:43:21 2001 UTC vs.
Revision 1.5 by root, Mon Jul 23 02:14:19 2001 UTC

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
8use Coro; 8use Coro;
9use Coro::Process;
10use Coro::Semaphore; 9use Coro::Semaphore;
11 10
12my $produced = new Coro::Semaphore 0; 11my $produced = new Coro::Semaphore 0;
13my $finished = new Coro::Semaphore 0; 12my $finished = new Coro::Semaphore 0;
14 13
15async { 14async {
16 for my $i (0..9) { 15 for my $i (0..9) {
17 print "produced $i\n"; 16 print "produced $i\n";
18 push @buffer, $i; 17 push @buffer, $i;
19 $produced->up; 18 $produced->up;
20 yield if @buffer > 5; # simulate memory pressure ;) 19 cede 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}; 23};
25 24

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines