Perlthrtut threadqueue example : possibly incorrect ?

Discussion in 'Perl Misc' started by klestes@gmail.com, Nov 28, 2006.

  1. Guest

    Messing with the example relating to the Thread::Queue, which is :

    use threads;
    use threads::shared;
    use Thread::Queue;

    my $DataQueue = new Thread::Queue;
    $thr = async {
    while ($DataElement = $DataQueue->dequeue) {
    print "Popped $DataElement off the queue\n";
    }
    };

    $DataQueue->enqueue(12);
    $DataQueue->enqueue("A", "B", "C");
    $DataQueue->enqueue(\$thr);
    sleep 10;
    $DataQueue->enqueue(undef);
    $thr->join;

    And I get an "invalid value for shared scalar". After further messing
    around, discovered it works OK if I remove the following line:

    $DataQueue->enqueue(\$thr);


    So my question is: Wha ?


    (Win32/ActiveState 5.8.7 in da house)
    , Nov 28, 2006
    #1
    1. Advertising

  2. Guest

    wrote:
    > Messing with the example relating to the Thread::Queue, which is :
    >
    > use threads;
    > use threads::shared;
    > use Thread::Queue;
    >
    > my $DataQueue = new Thread::Queue;
    > $thr = async {
    > while ($DataElement = $DataQueue->dequeue) {


    They should probably check for definedness, not just for truth,
    of the $DataElement.

    > print "Popped $DataElement off the queue\n";
    > }
    > };
    >
    > $DataQueue->enqueue(12);
    > $DataQueue->enqueue("A", "B", "C");
    > $DataQueue->enqueue(\$thr);
    > sleep 10;
    > $DataQueue->enqueue(undef);
    > $thr->join;
    >
    > And I get an "invalid value for shared scalar". After further messing
    > around, discovered it works OK if I remove the following line:
    >
    > $DataQueue->enqueue(\$thr);
    >
    > So my question is: Wha ?


    That is a limitation of Thread::Queue. I don't why they decided to
    give an example of this limitation without stating that that is what they
    were doing. Thread::Queue::Any should circumvent this problem.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Nov 28, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brett
    Replies:
    0
    Views:
    515
    Brett
    Dec 19, 2003
  2. dan byers
    Replies:
    1
    Views:
    584
    Hans =?iso-8859-1?Q?J=F8rgen?= Jakobsen
    Mar 6, 2004
  3. Edward
    Replies:
    7
    Views:
    1,396
    Edward
    Jun 11, 2004
  4. Sam Roberts
    Replies:
    15
    Views:
    276
    Sam Roberts
    Feb 7, 2005
  5. Replies:
    5
    Views:
    180
Loading...

Share This Page