http://www.perlmonks.org?node_id=671087

mude has asked for the wisdom of the Perl Monks concerning the following question:

hi guys.. im totally new with perl and was given an urgent task to make a multi-threading perl script...

problem:
i need to create multiple number of threads out of one... and fire them all up at once. i need to get the timing to make sure if all the process started simultaneously.

i came up with a module "Thread::Barrier" but, i don't have enough resources on how to use it.... been googling this module lately but i haven't seen anyone using it... i couldn't clearly understand the examples shown in this module...

for sure i used it in a wrong way...

objectives:
1. create multiple number of threads (user input) out of 1.
2. fire them all up at once..
3. get the timing to prove that these threads are all executed at the same time.

i tried making a script.... with just simple print as a process.... and i also used system "date" to check if the processes were executed at the same time....

can lead me to the right path guys... thanks
#!/usr/bin/perl use warnings; use threads; use threads::shared; use Thread::Barrier; my $br = Thread::Barrier->new; my $thr1 = threads->new(\&req); $thr1->join; sub req { $count=0; print "Enter number: "; $num = <STDIN>; my @thrlist; for (1..$num) #create number of threads { $thrlist[$_] = threads->new(sub { print"test\n"; syste +m("date"); }); $thrlist[$_]->join; $count++; } foreach (threads->list){ $br->wait; } print $br->wait; print "\n\ntotal number of threads $count\n\n"; }