Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Threading with a twist

by Random_Walk (Prior)
on Oct 03, 2017 at 05:17 UTC ( #1200567=note: print w/replies, xml ) Need Help??


in reply to Threading with a twist

Boss:

  • Waits for <STDIN>
  • Appends manipulated input to $TXQUEUE->enqueue()
  • Monitor $RXQUEUE and <STDIN> - simultaneously???
  • Sends <STDOUT> while(my $RESULT=$RXQUEUE->dequeue_nb()), until $RXQUEUE is empty. $RESULT is sent "AS-IS"

I would split that boss into two threads. A dispatcher listening on <STDIN> handing of work to workers and a publisher de-queueing the results from workers and publishing them to <STDOUT>

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^2: Threading with a twist
by Anonymous Monk on Oct 03, 2017 at 08:39 UTC
    Why?

      Because KISS

      The design in the OP gives two very disparate jobs to the 'Boss'. It must flip between checking if there are results on the results queue and handling them, then seeing if there is anything to read on <STDIN> and passing it off to workers. The OP is talking about using non blocking calls and sleeps to do this. The complexity clearly recognised by the multiplicity of punctuation marks ... Monitor $RXQUEUE and <STDIN> - simultaneously???

      If we split these two functions then we have two simple tasks.

      • Listen on <STDIN> and put work on worker queue.
      • Listen on results queue and publish results
      both tasks can be written with blocking calls ensuring they sleep efficiently until they have work, then spring to work with alacrity when there is something to do.

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!
        Having extra thread only for print is kiss?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1200567]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2021-04-18 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?