Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Relinquish cpu


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Kaptein   Prime Members   -  Reputation: 2180

Like
0Likes
Like

Posted 17 December 2013 - 10:50 AM

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.

 

 



Sponsor:

#2 codenine75a   Validating   -  Reputation: 9

Like
0Likes
Like

Posted 17 December 2013 - 11:51 AM

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



#3 SeanMiddleditch   Members   -  Reputation: 7269

Like
4Likes
Like

Posted 17 December 2013 - 12:26 PM

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().

#4 frob   Moderators   -  Reputation: 22841

Like
3Likes
Like

Posted 17 December 2013 - 04:15 PM

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.


Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS