Ctrl-z has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: from pseudofork to threads
by pg (Canon) on Feb 02, 2003 at 17:28 UTC | |
|
Re: from pseudofork to threads
by Ctrl-z (Friar) on Feb 02, 2003 at 15:59 UTC | |
by pg (Canon) on Feb 02, 2003 at 18:18 UTC |