Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Can someone please tell me why following script hangs. Main thread creates a thread (say "secondThread"). secondThread tries to create a thirdThread after sleeping for a while and that is where it hangs (i mean thirdThread is never created). Interesting thing is when main main thread prints something after I enter something on console the thirdThread is created. I am using ActiveState perl 5 on Windows (tried on XP and 7).
#!perl -w use strict; use threads; use Thread; use threads::shared; sub thirdThread { threads->detach(); printf "[%d] Third thread started\n",threads->tid(); } sub secondThread { threads->detach(); while(1) { sleep 2; printf "[%d] Going to start a new thread\n",threads->tid(); threads->create(\&thirdThread); } } threads->create(\&secondThread); while(<STDIN>) { print "CMD: ",$_,"\n"; if($_ eq "quit\n") { last; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Thread create hangs
by BrowserUk (Patriarch) on Sep 27, 2010 at 21:30 UTC | |
|
Re: Thread create hangs
by BrowserUk (Patriarch) on Sep 28, 2010 at 19:32 UTC | |
by Anonymous Monk on Sep 29, 2010 at 00:05 UTC | |
by Anonymous Monk on Sep 29, 2010 at 00:26 UTC | |
|
Re: Thread create hangs
by locked_user sundialsvc4 (Abbot) on Sep 28, 2010 at 13:52 UTC | |
by BrowserUk (Patriarch) on Sep 28, 2010 at 17:50 UTC | |
by Anonymous Monk on Sep 28, 2010 at 15:06 UTC |