File: prodcons1

package info (click to toggle)
libcoro-perl 6.570-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,144 kB
  • sloc: ansic: 2,560; perl: 2,122; makefile: 14
file content (36 lines) | stat: -rw-r--r-- 618 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl

# the classical producer/consumer example.
# one process produces items, send s a signal.
# another process waits for that signal and
# consumed the item.

use Coro;
use Coro::Signal;

my $produced = new Coro::Signal;
my $consumed = new Coro::Signal;
my $finished = new Coro::Signal;

async {
   for (0..9) {
      print "produced something\n";
      $produced->send;
      $consumed->wait;
   }
   print "work done\n";
   $finished->send;
};

async {
   while () {
      $produced->wait;
      print "consuming something\n";
      $consumed->send;
   }
};

$finished->wait;

print "job finished\n";