Added Thread/queue.t.
Malcolm Beattie [Thu, 2 Oct 1997 17:23:48 +0000 (17:23 +0000)]
p4raw-id: //depot/perlext/Thread@99

queue.t [new file with mode: 0644]

diff --git a/queue.t b/queue.t
new file mode 100644 (file)
index 0000000..c87dcee
--- /dev/null
+++ b/queue.t
@@ -0,0 +1,22 @@
+use Thread;
+use Thread::Queue;
+
+$q = new Thread::Queue;
+
+sub reader {
+    my $i;
+    for ($i = 1; $i <= 10; $i++) {
+       print "reader: waiting for element $i...\n";
+       my $el = $q->dequeue;
+       print "reader: dequeued element $i: value $el\n";
+    }
+}
+
+new Thread \&reader;
+my $i;
+for ($i = 1; $i <= 10; $i++) {
+    my $el = int(rand(100));
+    select(undef, undef, undef, rand(2));
+    print "writer: enqueuing value $el\n";
+    $q->enqueue($el);
+}