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

S

Stuart Moore

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;
 
B

Bryan Castillo

Stuart Moore said:
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);
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top