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:
or do whatever to send all running threads to the end of their code block.$SIG{INT} = sub{ foreach(@threads){$thread_exit{$_} = 1;} };
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).
In reply to Re: Thread detach
by zentara
in thread Thread detach
by ilanv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |