Im in the process of downloading Activstate 5.8 for Win32, and am keen to get
some threading shenanigans going on.
Ive used the pseudo-fork() with some success in 5.6 and have some code I'd like
to impliment in threads 'proper'.Ive read the perldocs and associated stuff,
but am not totally sure I'm getting it - particularly where i should be join()ing.
consider this pseudo-fork() code
would this be a similar implementation using threads - and if so, where should i be join()ing or detach()ing?foreach (1..10) { my $pid; print "$$ starting loop $_"; if( $pid = fork()) { print "$$ created child $pid"; } else { print "\t", "child $$ created ok"; sleep(int(rand(10))); print "\t", "child $$ done, outta here"; exit; } print "$$ exiting loop $_" if $pid; } # 1 while wait != -1; # *cough* print "$$ all done!";
use threads; foreach(1..10) { print "$$ starting loop $_"; my $kid = new threads(\&wasPsuedoFork); print "$$ exiting loop $_"; } sub wasPsuedoFork { print "\tchild ", threads->tid() " created ok"; sleep(int(rand(10))); print "\tchild", threads->tid() , " done, outta here"; }
In reply to from pseudofork to threads by Ctrl-z
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |