in reply to scalars, references and queues

Wonderful! you monks move so fast!

I think I still have some questions, but must digress into context to motivate them

My concept is to pipeline some data through several threads, passing data between threads via queues. I wish to put a reference to an anonymous hash on the first queue, then have the first thread take it off, read it's values, create one or more anonymous hashes and pass them on to the next queue.

The original hash does not get changed by the thread, though it's keys and values will get copied to all the new hashes created by the thread (for this iteration of the while

my $inqueueref = shift; my $outqueueref = shift; my %inhash; while (%inhash = $inqueueref->dequeue) { #create one or more new anonymous hashes and $outqueue->enqueue(\%ou +thash) }

).

Note that the relationship between the number of %inhashes and %outhashes is one:many.

Note that any given hash is only shared by two threads; the one creating it and the next one (reading it).

Now here's the follow-on question: How does the above solution using threads::shared change when the hashes are all anonymous hashes?

or do I need some monster "global array of hashes" package whith lots of thread-safe methods encapsulating it and protecting it from direct access by all these threads (possibly putting the array index on the queues in this implementation)? I sure hope not.

Replies are listed 'Best First'.
Re^2: scalars, references and queues
by Anonymous Monk on Aug 03, 2007 at 21:19 UTC

    Thanks to all. Some hard meditation and I've gotten to a simplified skeleton that I think solves everything. If you see anything worth warning me about, I would love to hear it.

    I'm putting the proof of concept code in <readmore> tags. The work file was called "sharedanonymoushashrefs.pl", so that explains some of the naming conventions (sahr_).