Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Trouble passing an array reference to my threads

by NetWallah (Canon)
on Nov 23, 2011 at 06:39 UTC ( [id://939604]=note: print w/replies, xml ) Need Help??


in reply to Trouble passing an array reference to my threads

The thread inherits a COW (Copy on write) copy of a part of the array, so updates to that will not affect the original.

What you need to do is to RETURN a value from your "sub pinger". This value can be collected when the thread is join()ed.
Use the returned value (Which can be an array ref, in fact, you can return $task) to update the array.

FWIW, I find the code style you used frightening, but am resisting the urge to comment on that. Should you choose to approach that subject, please request comment. I'm sure monks would be more than happy to share coding tips.

            "XML is like violence: if it doesn't solve your problem, use more."

  • Comment on Re: Trouble passing an array reference to my threads

Replies are listed 'Best First'.
Re^2: Trouble passing an array reference to my threads
by zwon (Abbot) on Nov 23, 2011 at 12:51 UTC
    The thread inherits a COW (Copy on write) copy of a part of the array

    There's no COW, it's just a copy created the same time the thread created.

      You are probably right - I made some assumptions based on my (limited) understanding of how threads are implemented - I thought I read somewhere that there is an underlying fork, which does COW.

                  "XML is like violence: if it doesn't solve your problem, use more."

        I think it is exactly opposite -- fork emulation implemented using threads on Windows

Re^2: Trouble passing an array reference to my threads
by dh (Novice) on Nov 23, 2011 at 13:27 UTC

    I don't want to frighten anyone with my code. This code was pulled out of the full script, so it may be more frightening in fragment than its original.

    Some of the mess in the code, like not returning from the threads, comes from the fact that this code wasn't threaded until I realized there may be too many hosts to iterate quickly enough. Originally, it just passed from sub to sub for each host in step. I am going to try returning that value from a join tonight to keep the reference inside the thread caller.

    I would absolutely like to hear your comments on how the style and methodology may be improved. This code will be running for a while, so I want it to run well.

    Thank you!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found