How to add a delay without relinquishing the CPU Cycle in C. Sleep actually relinquishes the CPU cycle from the current thread, but is there a way to make it wait without using sleep?
Asked
Active
Viewed 671 times
0
-
2while(1){ if(time_now()) break; } ? – lulyon Sep 10 '13 at 03:45
-
2Busy wait. http://en.wikipedia.org/wiki/Busy_waiting – Adam Burry Sep 10 '13 at 03:48
-
Seems to be a duplicate of the question http://stackoverflow.com/questions/1107593/what-are-trade-offs-for-busy-wait-vs-sleep – buddy Sep 10 '13 at 05:22
1 Answers
0
Blocking calls are not "busy waiting" or "spin locks". Blocking calls are sleepable -- that means the CPU would work on other task, no cpu are wasted.
As to delay without relinquishing the CPU cycle in linux
Blocking calls are easier -- they are easy to understand, easier to develop, easier to debug.
But they are resource hog. If you don't use thread, it would block other clients; If you use thread, each thread would take up memory and other system resource. Even if you have plenty of memory, switching thread would make the cache cold and reduce the performance.
This is a trade off -- faster development and maintainability? or scalability. Through this we can delay it.

George Dodge
- 31
- 1