Relinquish cpu

Started by
2 comments, last by frob 10 years, 4 months ago

I'm implementing a wait() function, which I want to be multiplatform, and hopefully not use sleep().

Are there any functions on win and linux that allows you to just relinquish cpu time immediately?

I realize that sleep() does this, but I want to know what the alternatives are?

I'm guessing there are none, but I'm asking anyways.

Advertisement

I do not like the sleep function because it causes a fixed delay. I would loop a little bit and use the clock function. It is under the ctime namespace or I believe time.h

pthread_yield on Linux and most UNIXes and SwitchToThread on Win32. If you're using only recent c++ toolchains you can also use std::this_thread::yield().

Sean Middleditch – Game Systems Engineer – Join my team!

Neither system is a real-time operating system. You can yield your time, but there are no guarantees about when the OS will reschedule you.

In fast-paced games usually the best bet is to wait for the screen buffer to flip. The major rendering APIs have blocking calls for that.

This topic is closed to new replies.

Advertisement