morgon has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to get to grips with Perl-threads and I have the following problem on a 5.8-Perl that I have to use (where you don't seem to be able to share objects):
What I want to do is use Thread::Queue to pass data from one thread to another (one enqueues, the other dequeues).
Now this is very easy to do if you can create your Queue before you spawn the threads as then both threads have acccess to the queue.
What I want to do now is to create a thread (let's call it thread1) and then some time later create another thread (thread2) together with a queue and use the queue to pass data between thread1 and thread2.
What I cannot figure out is how thread1 can get access to the queue (which is an object and so cannot be shared in an easy way)...
Is that simply not possible? How would I use other ways of inter-thread-communication to pass data from thread1 to thread2?
Evidently in the case of just two threads you can arrange for the queue to be created beforehand but ultimately I want to deal with a situation where you do not know in advance how many threads there will be in the end (e.g. a new thread gets created for every network-connection) and all the new threads have to be able to dequeue data that a "producer"-thread fills.
Many thanks for all suggestions...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: threads and queues
by ikegami (Patriarch) on Apr 02, 2009 at 21:25 UTC | |
by morgon (Priest) on Apr 02, 2009 at 21:49 UTC |