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

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top