Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Does the main thread yield?

by Random_Walk (Prior)
on Apr 24, 2013 at 07:15 UTC ( [id://1030291]=perlquestion: print w/replies, xml ) Need Help??

Random_Walk has asked for the wisdom of the Perl Monks concerning the following question:

I am using threads and I want the main thread to give some time to its workers. The main thread enqueues work for them and I don't want the queue to get too big. The docco says: You may do use threads qw(yield), and then just use yield() in your code. I am using it in the main thread with no errors but I am not sure it is doing anything.

At this point I am early in development and there is not much load on my system. If yield is not working in the main thread would doing a uSleep have a similar effect? Any other suggestions on an efficient way to keep the queue full but not too full?

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re: Does the main thread yield?
by BrowserUk (Patriarch) on Apr 24, 2013 at 07:40 UTC
    Any other suggestions on an efficient way to keep the queue full but not too full?

    Try my self-limiting queue implementation from the spoiler in Re^4: dynamic number of threads based on CPU utilization.

    Set the size to at least 4 times the number of elements as you have consumer threads and then adjust up and down until you hit the sweet spot for your application.


    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.

      Thank you. I will be using that, a much more elegant solution

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1030291]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-28 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found