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