Fun with Threads - "Attempt to free unreferenced scalar during globaldestruction."

Discussion in 'Perl Misc' started by Stuart Moore, Jun 27, 2003.

  1. Stuart Moore

    Stuart Moore Guest

    My aim is to have a module, "ToolsThread", which I can pass commands to so
    that it'll execute them in its own thread. However when I call join on the
    thread, it seems to all go wrong. It all behaves as normal up to the point
    I call join on the thread in the quit function, then it gives me the
    message

    Attempt to free unreferenced scalar during global destruction.

    I'm not sure what that means, but I don't like it.

    Here is the relevant code (ToolsThread.pm is the module, testToolsThread
    is a basic test script. I would have more code in the loop eventually,
    assuming I can get it to work)

    ##ToolsThread.pm
    package ToolsThread;

    use strict;
    use warnings;
    use threads;
    use threads::shared;
    use Thread::Queue;

    our $queue = new Thread::Queue;
    our $thread = threads->create(\&Run,$queue);

    sub Run{
    my $queue = shift;
    while(1){
    my $incoming = $queue->dequeue;
    if ($incoming eq "quit"){
    last;
    }
    }
    }

    sub Quit{
    $queue->enqueue('quit');
    $thread->join();
    }

    ##testToolsThread.pl
    use strict;
    use warnings;
    use threads;
    use threads::shared;
    use Thread::Queue;
    use ToolsThread;

    ToolsThread::Quit;
     
    Stuart Moore, Jun 27, 2003
    #1
    1. Advertising

  2. Re: Fun with Threads - "Attempt to free unreferenced scalar during global destruction."

    Stuart Moore <> wrote in message news:<>...
    > My aim is to have a module, "ToolsThread", which I can pass commands to so
    > that it'll execute them in its own thread. However when I call join on the
    > thread, it seems to all go wrong. It all behaves as normal up to the point
    > I call join on the thread in the quit function, then it gives me the
    > message
    >
    > Attempt to free unreferenced scalar during global destruction.
    >
    > I'm not sure what that means, but I don't like it.
    >
    > Here is the relevant code (ToolsThread.pm is the module, testToolsThread
    > is a basic test script. I would have more code in the loop eventually,
    > assuming I can get it to work)
    >
    > ##ToolsThread.pm
    > package ToolsThread;
    >
    > use strict;
    > use warnings;
    > use threads;
    > use threads::shared;
    > use Thread::Queue;
    >
    > our $queue = new Thread::Queue;
    > our $thread = threads->create(\&Run,$queue);


    # change to this (I don't know why it is like this though)
    our $thread = threads->create("Run",$queue);

    >
    > sub Run{
    > my $queue = shift;
    > while(1){
    > my $incoming = $queue->dequeue;
    > if ($incoming eq "quit"){
    > last;
    > }
    > }
    > }
    >
    > sub Quit{
    > $queue->enqueue('quit');
    > $thread->join();
    > }
    >
    > ##testToolsThread.pl
    > use strict;
    > use warnings;
    > use threads;
    > use threads::shared;
    > use Thread::Queue;
    > use ToolsThread;
    >
    > ToolsThread::Quit;
     
    Bryan Castillo, Jun 28, 2003
    #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. Andy Fish
    Replies:
    65
    Views:
    1,754
    Mabden
    May 18, 2004
  2. yoda
    Replies:
    2
    Views:
    429
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  3. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    396
    William Ahern
    Aug 27, 2004
  4. dolphin
    Replies:
    4
    Views:
    318
    Jorgen Grahn
    Aug 25, 2007
  5. er
    Replies:
    2
    Views:
    507
Loading...

Share This Page