Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Threading in a loop

by TomDLux (Vicar)
on Apr 24, 2013 at 19:35 UTC ( [id://1030498]=note: print w/replies, xml ) Need Help??


in reply to Threading in a loop

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1030498]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2025-07-20 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.