in reply to Thread detach

Since you seem to be learning threads....I'll "pound in" the basic lesson, which seems to elude most thread programmers, until they "learn by experience".

In addition to the comment,by BrowserUk,about your "endless loop" in a thread, a thread will NOT return until it gets to the end of it's code block. It is mentioned in the docs for threads, but it isn't emphasized enough, and most programmers don't "absorb it's meaning" until they run into the warnings.

So whether you detach, or wait to join, that warning will be there when you exit the program. You've noticed that BrowserUk's example uses a "countdown", which assures that the thread code finishes.

You must have a mechanism, thru code design(like countdown or alarm), or some signal sent thru shared variables, to tell the thread to go to the end of it's code block, when finished. Even "sleeping threads" need to have this done, or you will get warnings.

You may even have to catch SIG{INT}, in case you hit control-c, to shutdown the threads before exiting. Like:

$SIG{INT} = sub{ foreach(@threads){$thread_exit{$_} = 1;} };
or do whatever to send all running threads to the end of their code block.

So, repeat 100 times, "a thread must reach the end of it's code block, or there will be warnings (but maybe no harm done).


I'm not really a human, but I play one on earth. flash japh