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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.