Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How to create separate threads for concurrent execution?

by Perllace (Acolyte)
on Mar 14, 2011 at 10:06 UTC ( [id://893060]=perlquestion: print w/replies, xml ) Need Help??

Perllace has asked for the wisdom of the Perl Monks concerning the following question:

I'm running a script, and in the middle of script execution I want to capture system performance data print it and then continue with the script execution.
Obj->GetSystemInfo($s,$name,$App)
Inside this function, I have separate subroutines to handle each kind of information such as RAM, Heapinfo etc., I want each subroutine to run on a separate thread and retrieve the necessary information. How can I make this happen ? If I do it this way, only the cputhread output gets printed on the console.
$RAMthread = threads->new(sub{$self->GetFreeRAM($serial)}); $heapthread = threads->new(sub{$self->Getheap($serial)}); $cputhread = threads->new(sub{$self->Getcpu($serial)});
Thank you, Perllace

Replies are listed 'Best First'.
Re: How to create separate threads for concurrent execution?
by BrowserUk (Patriarch) on Mar 14, 2011 at 10:12 UTC

    Update: Hm. Old, tired eyes. What did I think I read.

    Forget this bollocks and I'll try again:


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: How to create separate threads for concurrent execution?
by ikegami (Patriarch) on Mar 14, 2011 at 17:49 UTC
    You are launching three threads, and they are running in parallel. As to why only one of them creates output, we have no clue since we know nothing of the code that runs in each thread.
Re: How to create separate threads for concurrent execution?
by BrowserUk (Patriarch) on Mar 14, 2011 at 17:35 UTC
    only the cputhread output gets printed

    What is "cputhread output"? and how does it differ from what you are expecting or wanting?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-03-19 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found