2006/11/10

Using return + Multithread

There is a 'join' function in Perl when using threads module.


use threads;
use threads::shared;

my @t;
for my $i (1..$num)
{
push @t, threads->new(\&ajxss_wt, $i, $name[$i]);
}
for (@t) { $_->join;}

print "something";


Without 'join' here, "something" will be print immediately, but with 'join', print function will hold until every thread ends.

How to know if thread ends? It will check the return value from 'ajxss_wt' function.
So return 1 must have at the end of 'ajxss_wt' function.

As I found, it is better to make ajxss_wt simple.

Note: For a large number of threads, this code does not work well in cgi-bin. But we can embed this piece of code into system call.

Update: Just found firefox may not be able to support multithread in my case, but IE works fine.

No comments:

Post a Comment