Re: perl threads



On Thu, 28 Aug 2008 02:02:38 -0700 (PDT), kath <nitte.sudhir@xxxxxxxxx>
wrote:

know 'Perl ithreads are not lightweight!', i am using carefully, in
the sense, I'm not using any shared variables between threads. Each
thread will do dependency calculation, which will produces an output
in a file separately. Later i parse those files to get dependency list
for each project.

First I don't use win32, I use linux, but the advice should be the same
in this case.
If you don't share variables between threads, and you are writing
results to a file, to be processed later, you don't need threads.
Forking an independent process is better. (I realize on win32 it's all
threads, but Perl imposes it's own weight when using threads, so you
are better off with independent processes.

See the part on Win32::Process in
http://perlmonks.org?node_id=500663



Problem:
Sometimes* the script waits forever or the script just hangs. That is
waiting for threads. And cant continue with other scenario.

Threads must reach the end of their code blocks, or return, in order
for them to be joined. Maybe try detached threads, or use a shared
variable to signal them to return.

[code]
#this way i create threads
#foreach scenario() ...{
map {my $th = threads->create(\&worker, $_)} @$proj_arr; #proj_arr has
projects of a scenario
# ...}

# This is how i wait for all threads to finish its job
print "waiting for threads to finish";
map {my $k = $_->join} threads->list;
[/code]

Is there a way i can overcome this? Or my perception about cause for

Somewhere in your worker code block, you must listen for a shared
variable, telling the thread to immediately return. Later threads
versions have kill signals you can send to threads, but I don't know if
they work on win32. A thread will not end, just by telling it to join.

zentara

--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html
.