...the difference between a thread and a process...

If you're using Perl threads, you shouldn't have to worry about whether it is actually implemented using processes or real threads™. That's why they're "Perl threads".

Having said that, to my knowledge, Linux is the only system where you can actually think of threads as processes, as having seperate program id's (pid's, $$). This allows modules as Thread::Signal to function in that environment. Win32 only knows about real threads and mimics fork() using threads. Other *nixes are somewhere inbetween. Some can fork() and have real threads (Solaris seems to fall in that group). But e.g. on Mac OS X (and presumably other BSD's), threads look as seperate processes, but can not be signalled.

...never-ending sub (ie it's got a while (1) loop)m how can I stop it nevertheless?

Use a shared variable in the while. So:

while (1) {
becomes:
while ($sharedvar) {
and reset the shared variable in another thread when you want to have the thread in question stop.

In that respect, you might also want to have a look at Thread::Queue::Monitored and/or Thread::Conveyor::Monitored.

Hope this helps.

Liz

Update:
I forgot one other way to do this. This will only work if you are running under Linux for now. Use Thread::Signal to activate a handler that will do a Thread::Exit. No nice cleanup that way, but definitely effective ;-)


In reply to Re: returning from a thread ? by liz
in thread returning from a thread ? by Foggy Bottoms

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.