How would I make a version of sleep in C spin so it uses cpu cycles?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What you want to do is a busy wait where you loop until a certain amount of time has elapsed. Just get the current time (using the highest precision timer available) and loop until the current time is a certain amount of time after you started.
Here’s a concrete example using the Windows API and the performance counter using the two associated functions,
QueryPerformanceCounter()andQueryPerformanceFrequency().Use the appropriate API in your case, whatever that may be.