Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I've encountered strange behavior in a script, where I read and write to the same variable repeatably and rapidly. It seems the issue is that the read operation happens before the previous write finishes, and I get errors. Example code:
my @array = ( some values ); While ( my_condition ) { $buffer = $array[0]; $array[0] = new_value; mytestfunc(\@array); $array[0] = $buffer; }
Before long, $array[0] != $buffer. But, if I change the code to the following, my errors disappear.
While ( my_condition ) { $buffer = $array[0]; $array[0] = new_value; mytestfunc(\@array); $array[0] = $buffer while ($array[0] != $buffer); }
Is there a better way to handle this issue? Thanks for the wisdom and advice.
Jeff
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: volatile memory?
by rovf (Priest) on Sep 02, 2010 at 07:56 UTC | |
by kjcdb8er (Initiate) on Sep 02, 2010 at 08:11 UTC | |
by wwe (Friar) on Sep 02, 2010 at 10:10 UTC | |
by renshui (Novice) on Sep 02, 2010 at 09:29 UTC | |
|
Re: volatile memory?
by DrHyde (Prior) on Sep 02, 2010 at 09:56 UTC | |
|
Re: volatile memory?
by JavaFan (Canon) on Sep 02, 2010 at 10:49 UTC |