Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Using Select and pipes to communicate with threads

by jdrago999 (Pilgrim)
on Sep 02, 2011 at 01:41 UTC ( [id://923742]=note: print w/replies, xml ) Need Help??


in reply to Using Select and pipes to communicate with threads

Very Cool!

Question: How would you modify this so that the main process could send messages/data to the threads?

I don't have a true multi-processor system, so I can't say whether this is faster than just running one big sequential file, but it is a useful techique for monitoring the output of threads.

My machine has 8 cores (Intel Core i7) and this is the result after running it:

jdrago999@e6510:~$ time perl Desktop/thread-prime.pl ........lots of output here.......... real 0m3.314s user 0m11.540s sys 0m0.490s

Replies are listed 'Best First'.
Re^2: Using Select and pipes to communicate with threads
by zentara (Archbishop) on Sep 02, 2011 at 09:06 UTC
    How would you modify this so that the main process could send messages/data to the threads?

    Pass 2 pipes to each thread? set the second pipe as reader in the thread and writer in the main thread. Probably you would have to stuff the pipe filehandles in a hash in the main thread, so you could keep track of which pipe writes to which thread. I suppose you can run IO::Select in each thread to watch for messages, or setup an eventloop to watch the filehandle, or a basic loop of some sort.

    I will work on an example. :-)


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found