Threads and sharing global variable

A

anguyen

Hi,
I am having a global array @gDone, and after spawning a number
threads, each would set the corresponding element to TRUE to signify
it has done its work so the parent thread could stop waiting.
It seems like the update of @gDone is not seen in the parent thread.
The print of $gDone[$tid] is always either FALSE or undef, depending
on how I set it in the parent thread.
Can someone help providing an explanation for this?
Anh-
 
L

Leon Timmermans

Hi,
I am having a global array @gDone, and after spawning a number threads,
each would set the corresponding element to TRUE to signify it has done
its work so the parent thread could stop waiting. It seems like the
update of @gDone is not seen in the parent thread. The print of
$gDone[$tid] is always either FALSE or undef, depending on how I set it
in the parent thread. Can someone help providing an explanation for
this? Anh-

You haven't posted any code, did you use thread::shared?

Leon Timmermans
 
Z

zentara

Hi,
I am having a global array @gDone, and after spawning a number
threads, each would set the corresponding element to TRUE to signify
it has done its work so the parent thread could stop waiting.
It seems like the update of @gDone is not seen in the parent thread.
The print of $gDone[$tid] is always either FALSE or undef, depending
on how I set it in the parent thread.
Can someone help providing an explanation for this?
Anh-

A couple of possible explanations:
1. You set the values of the array before you declared it shared.
2. The parent thread will not automagically see the changes in the array
due to a thread action, you must active read it in the main thread to
update it. This is a problem in Gui's and threads, where you need a
timer run in the main thread to constantly re-read the array at a fast
interval.

Otherwise, show a minimal code example that runs and demonstrates the
problem.

zentara
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top