Your concept is to have two threads, one of which modifies the variable, and the other immediately prints out the new value. Unfortunately, multi-threaded programs don't work like that. Without any communication between the threads, one thread will modify the variable 0 or more times, then the other will print the variable o or more times, and back and forth. There are no guarantees.
If you want to display what is happening with a variable, you should 'tie' it to a class, as described in http://perldoc.perl.org/functions/tie.html. I believe you would only need to implement a STORE() routine, which would print out the current value of the variable. That way, modifying the variable would cause the value to be displayed.
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
In reply to Re: Threading in a loop
by TomDLux
in thread Threading in a loop
by jerre_111
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |