This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Added Thread/queue.t.
[perl5.git] / queue.t
CommitLineData
19be36ba
MB
1use Thread;
2use Thread::Queue;
3
4$q = new Thread::Queue;
5
6sub reader {
7 my $i;
8 for ($i = 1; $i <= 10; $i++) {
9 print "reader: waiting for element $i...\n";
10 my $el = $q->dequeue;
11 print "reader: dequeued element $i: value $el\n";
12 }
13}
14
15new Thread \&reader;
16my $i;
17for ($i = 1; $i <= 10; $i++) {
18 my $el = int(rand(100));
19 select(undef, undef, undef, rand(2));
20 print "writer: enqueuing value $el\n";
21 $q->enqueue($el);
22}