Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Perl threads are not ready for Prime Time.

What does that mean? Who said it? And how will you know unless you try it?

Does it get easier? Of course, the devil is in the details, but then, you didn't give us any.

#! perl -slw use strict; use threads; use Thread::Queue; use Data::Dumper; our $QMAX ||= 1000; our $TMAX ||= 3; our $N ||= 1000000; my $Q = new Thread::Queue; sub thread { my $tid = threads->self->tid; for( 1 .. $N ) { $Q->enqueue( join ':', $tid, int rand( 10 ) ); select undef, undef, undef, 0.01 while $Q->pending > $QMAX; } $Q->enqueue( undef ); } threads->new( \&thread )->detach for 1 .. $TMAX; my %collate; for ( 1 .. $TMAX ) { while( my $data = $Q->dequeue() ) { my( $src, $value ) = split ':', $data; $collate{ $src }{ $value }++; } } print Dumper \%collate;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re: Reliable asynchronous processing by BrowserUk
in thread Reliable asynchronous processing by Codon

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 having a coffee break in the Monastery: (5)
As of 2024-03-28 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found