Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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 :)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.

The start of some sanity?


In reply to Re^3: any module with streaming pipe implementation for use with threads (Correction. Sort of.) by BrowserUk
in thread any module with streaming pipe implementation for use with threads by Rohan_Bhatia

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 03:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found