Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Threads and sharing global variable

Reply
Thread Tools

Threads and sharing global variable

 
 
anguyen@redhat.com
Guest
Posts: n/a
 
      09-03-2008
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-
 
Reply With Quote
 
 
 
 
Leon Timmermans
Guest
Posts: n/a
 
      09-03-2008
On Wed, 03 Sep 2008 09:44:02 -0700, anguyen wrote:

> 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
 
Reply With Quote
 
 
 
 
zentara
Guest
Posts: n/a
 
      09-04-2008
On Wed, 3 Sep 2008 09:44:02 -0700 (PDT), http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

>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


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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
Threads modify "global" variable -- asking for trouble? J Rice Python 5 03-18-2006 08:56 PM
Is mymodule.myvariable a 'global'? (What is proper definition of 'global variable'?) seberino@spawar.navy.mil Python 1 08-21-2005 09:21 PM
Use Global Variable or Global Struct??? Bryan Parkoff C++ 2 11-27-2004 02:46 AM



Advertisments