Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Threads and sharing global variable
September 3, 2008, 4:44 pm
rate this thread
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?
Re: Threads and sharing global variable
On Wed, 3 Sep 2008 09:44:02 -0700 (PDT), firstname.lastname@example.org wrote:
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
Otherwise, show a minimal code example that runs and demonstrates the
I'm not really a human, but I play one on earth.
- » "Selling" Perl (i.e. getting the boss to let me install it)
- — Previous thread in » PERL Discussions