Jump to content
  • Advertisement
Sign in to follow this  
TheFallen

Priority of boost::thread

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, anyone here using boost::thread? I would like to use it for a game, but I can't find a way to set the priority of a new thread... How can I do that? I think threads, where you can't change the priority, are not very useful... thx, fallen

Share this post


Link to post
Share on other sites
Advertisement
I am just learning to use boost::thread...

Out of curiosity, why would you want to change the priority of a thread? I haven't much experience in the matter, but from what I have seen, it really isn't necessary to change a thread's priority to get decent performance. Mind you, I don't have much experience in such matters...

Share this post


Link to post
Share on other sites
As of 2003 setting the priority of threads was still in the design phase and I haven't seen much about them since then. I assume it's very difficult to make it portable. You might find something being worked on in the dev branch.

There are other ways of controlling boost threads manually. For example in my application the thread that generates procedural textures sleeps for a while after all tasks are complete. It wakes up periodically to check the queue for more work effectivly reducing it's priority and overhead. This won't work for all situations, of course, but sleep(time) and yield() can be very useful.

Share this post


Link to post
Share on other sites
Quote:
Out of curiosity, why would you want to change the priority of a thread? I haven't much experience in the matter, but from what I have seen, it really isn't necessary to change a thread's priority to get decent performance. Mind you, I don't have much experience in such matters...


In games, you mostly use threads to do some stuff in background. These threads should have lower priority than the main thread, so that they get less time for execution. Think of MidoriKid's example (loading textures in background). There are games, where you have lots of textures, so that you have to (un-)load them dynamically. Now you could do some suggestions, what textures you will need within the next - let's say - 2 seconds. For these a loading time about 1 second would be okay, because the texture is not actually needed. But because it needs so long, the required CPU power is very low und doesn't affect the other tasks in the game (like rendering, KI, etc...).

Quote:

As of 2003 setting the priority of threads was still in the design phase and I haven't seen much about them since then. I assume it's very difficult to make it portable. You might find something being worked on in the dev branch.


Damn...

Quote:

here are other ways of controlling boost threads manually. For example in my application the thread that generates procedural textures sleeps for a while after all tasks are complete. It wakes up periodically to check the queue for more work effectivly reducing it's priority and overhead. This won't work for all situations, of course, but sleep(time) and yield() can be very useful.


The problem: in the extra thread most of the time I call methods, that are used also in the main thread, so I can't do much yielding (and of course I don't even have a pointer to the thread object there)...
Of course the thread sleeps some time after an iteration of the main loop and only awakes every 100ms. But the stuff I have to do in the thread takes to long, so the break in performance is obvious every time the thread awakes...

fallen

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!