Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an alternative for sleep() in C?

Tags:

c

delay

sleep

In traditional embedded programming, we will give a delay function like so:

for(i=0;i<255;i++)
   for(j=0;j<255;j++);

In the microprocessor's view, is this how the sleep() function works?

Is there an alternative for the sleep() function in C?

like image 454
Manoj Doubts Avatar asked Nov 05 '08 04:11

Manoj Doubts


1 Answers

The kind of loop you describe is called a "busy wait". In real operating systems, sleeping does not cause a busy wait; it tells the operating system to not schedule the process in until the sleep period is over.

like image 84
Chris Jester-Young Avatar answered Sep 30 '22 18:09

Chris Jester-Young