in reply to multithreading sample needed
P.S. It's actually more complicated in real life scripts, so don't be dazzled by this simplistic example. :-)
#!/usr/bin/perl use warnings;; use strict; use threads; for (1..10) { print "hello $_ from main\n"; } for (1..10){ threads->create( \&thread, $_ )->detach; } print "all done, press the Enter key to exit\n"; <>; # this is done so the main thread dosn't exit before # the threads can finish sub thread { my $val = shift; foreach my $x (1..10) { print "hello $x from thread $val\n"; #select( undef,undef,undef,.5); #half second sleep } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: multithreading sample needed
by sweepy838 (Acolyte) on May 01, 2012 at 18:22 UTC | |
by roboticus (Chancellor) on May 01, 2012 at 18:33 UTC | |
by BrowserUk (Patriarch) on May 01, 2012 at 18:44 UTC | |
by zentara (Cardinal) on May 02, 2012 at 10:31 UTC |