Priority of boost::thread

Started by
2 comments, last by TheFallen 18 years, 8 months ago
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
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...
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.
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

This topic is closed to new replies.

Advertisement