Threading problem.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   csaf_toiu
Posted On:   Sunday, June 13, 2004 01:44 AM

I have a thread running in the background which at times does nothing, and at other times needs to calculate as much as it can. When it does nothing, calling sleep(50) every loop works very well, this lets the CPU go free to do more important things than loop as much as possible. When it does something, I want it to use as much CPU as possible. However, if I simply let it go, it will slow down the computer immensely. The solution I have now is to simply sleep for five milliseconds every 50 milliseconds. This works fine, as it lets the computer do other things. But it doesn't use the full potential it can. What I really want is something like SETI@home: use as much CPU as possible without disturbing the running of the rest of the    More>>

I have a thread running in the background which at times does nothing, and at other times needs to calculate as much as it can. When it does nothing, calling sleep(50) every loop works very well, this lets the CPU go free to do more important things than loop as much as possible.


When it does something, I want it to use as much CPU as possible. However, if I simply let it go, it will slow down the computer immensely. The solution I have now is to simply sleep for five milliseconds every 50 milliseconds. This works fine, as it lets the computer do other things. But it doesn't use the full potential it can.


What I really want is something like SETI@home: use as much CPU as possible without disturbing the running of the rest of the computer. How could one do this?

   <<Less

Re: Threading problem.

Posted By:   Edward_Harned  
Posted On:   Sunday, June 13, 2004 09:08 AM

You should use wait() notify(), not sleep(). This way the thread is only active when you have work for it.


You should set the priority setPriority() of the thread to a proper (whatever that means) value so that other threads get cpu time.


You should use yield() in place of the sleep(5) to give other threads cpu time.


Naturally there are other methods depending on your specific needs.

About | Sitemap | Contact