4 $q = new Thread::Queue;
7 my $tid = Thread->self->tid;
11 print "reader (tid $tid): waiting for element $i...\n";
13 print "reader (tid $tid): dequeued element $i: value $el\n";
14 select(undef, undef, undef, rand(2));
17 print "reader (tid $tid) returning\n";
25 for (my $i = 0; $i < $nthreads; $i++) {
26 Thread->new(\&reader, $i);
29 for (my $i = 1; $i <= 10; $i++) {
30 my $el = int(rand(100));
31 select(undef, undef, undef, rand(2));
32 print "writer: enqueuing value $el\n";
36 $q->enqueue((-1) x $nthreads); # one end marker for each thread