mrd has asked for the wisdom of the Perl Monks concerning the following question:
I'm having some trouble with Thread::Queue::Any. I managed to reduce the problem to the following :
If I run the code as is, the output reads:############# code starts here ############# use strict; use threads; use threads::shared; use Thread::Queue::Any; our $| = 1; my $QUEUE : shared; my $TERMINATE : shared = 0; my $THREAD; sub TimeThread { while (!$TERMINATE) { sleep 1; $QUEUE->enqueue(scalar(localtime())); } } $SIG{TERM} = sub { $TERMINATE=1; $THREAD->join; exit; }; $QUEUE=Thread::Queue::Any->new; $THREAD=threads->new(\&TimeThread); while (1) { sleep 1; if ($QUEUE->pending) { ######## This is really weird! ######## my $time = $QUEUE->dequeue; print $time; ### NOT OK #print $QUEUE->dequeue; ### OK. } } ############# code ends here ##################
1111 ...
and so on.
Now if I replace line no. 37 with:
I get the expected result, namely nicely formatted localtime()s.print $QUEUE->dequeue;
What am I doing wrong ?
Thank you,
R.
PS: My environment is : WinXP Home Edition; ActivePerl 5.8.3 Build 809; Thread::Queue::Any 0.06
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Thread::Queue::Any->dequeue trouble
by chromatic (Archbishop) on Aug 25, 2005 at 21:49 UTC | |
by mrd (Beadle) on Aug 26, 2005 at 07:13 UTC | |
|
Re: Thread::Queue::Any->dequeue trouble
by NetWallah (Canon) on Aug 26, 2005 at 03:50 UTC |