According to the author of the original post, he has already considered shared variable, and he described the problem with that, so that's not what he asked for.
No, Thread::Signal is not a better option, and it is even not an option. this problem is more difficult than it sounds.
The problem described in the original post is not that he can not receive signal, on the contrary, he can receive signal with no problem. The same problem (the real problem) exists for both threads module and Thread::Signal module. What he really had problem with is how to instrcut the spider thread to stop. Assume he received a signal or anhthing similar, what he should do to stop the spider thread.
If you don't care whether the program stops decently, the thing becomes much easy. If Tk runs on main thread (most likely), just have a button, when the user clicks it, exit. For example:
use Tk; use IO::Socket::INET; use threads; use strict; use warnings; $| ++; threads->create(\&a); my $mw = MainWindow->new(title => "window"); $mw->Button(text => "exit", command => sub {exit})->pack(); MainLoop; sub a { sleep(10000); }
If he wants to quit, he can quit, just whether it is decent enough to the author's standard.
A real problem he might encounter is that the spider thread can take up lots of CPU cycles, and makes the Tk thread not responding. In that case, what he needs is make the spider thread yields (threads module delivers this) periodically, so the Tk thread get a chance to run.
In reply to Re: Re: Perl threads - telling them urgent stuff
by pg
in thread Perl threads - telling them urgent stuff
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |