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
In reply to Thread::Queue::Any->dequeue trouble by mrd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |