in reply to Re^2: any module with streaming pipe implementation for use with threads
in thread any module with streaming pipe implementation for use with threads
can we use them with datatypes that are not shared?
In my first reply, I said you can only queue scalars. I was wrong. After a fashion.
The original Thread::Queue module, which is unfortunately no longer available on CPAN for some reason, was a wonderfully simple module that consisted of just the constructor and four methods: enqueue(), dequeue(), pending() and the little used but sometimes useful dequeue_nb().
The perfect example of a module that did just what it need to do to satisfy it name, and did it quietly and efficiently. With an interface so simple that you never have to look it up(*see later). It looked like this:
Simple and beautiful. And it only allowed scalars to be shared.
But you remember I mentioned never having to look up the docs? Well, long after I posted my first reply, I was watching a movie when I remembered that the module had been upgraded a while back and some new (mis)features were added. I did play with them once, but since I never need them, I'd forgotten about them.
In addition to sprouting a bunch of unnecessary and definitively un-queue-like methods: peek(), insert() & extract(), it also gained the ability to convey references to arrays and hashes. I remember thinking this was a cute idea when I first saw it. Until I ran a few tests that is.
This conveys arrays using my join/split method:
This does the same thing using references:
And here are a couple of comparative runs of both:
c:\test>junk51 -T=10 -N=100 -I=1e4 Took 2.544000 seconds 4.742 2.137 0 0 c:\test>junk52 -T=10 -N=100 -I=1e4 Took 22.028000 seconds 16.832 29.296 0 0 c:\test>junk51 -T=10 -N=1000 -I=1e3 Took 2.148000 seconds 3.541 1.809 0 0 c:\test>junk52 -T=10 -N=1000 -I=1e3 Took 21.426000 seconds 15.303 29.156 0 0
It really is hard justify why queueing array references is 10 times slower than joining and spliting them. Especially if you look at the processor usage rather than wall clock and realise that it takes 55 seconds cpu for the former and only 5 for the latter.
So, after all that. Yes, you can share other datatypes, but you probably don't want to. At least I don't :)
|
|---|