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; } }
In reply to Thread create hangs by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |