I need to delay execution of some parts of my codes. I am Ubuntu user so, I can not use <windows.h> and its sleep(minutes) function. The codes which i am using is working but it uses actual loop and one core of my CPU. I want to delay (sleep) my codes tens of minutes or even hour's.
So, I am looking for other solution which will be less suffering for my CPU.
I still don't know why everyone's using delay(), sleep(), or Sleep() when they can write a function that's cross-platform and maybe not as generally awesome as initially presumed after a small discovery regarding the nature of those functions.
When platform-specific code does it better, use it.
The whole point of sleep functions is to yield execution time to other processes. Using <ctime> stuff just puts you in a loop that eats processor time.
I disagree with the fundamental statement behind your statement "When platform-specific code does it better, use it", however if indeed the sleep functions return execution time to other processes for a period, then indeed I will admit that they are a better solution than ticking off clocks for the purposes of not doing anything for a specific period of time.
My mind is made up. I don't fully agree with your statement command "When platform-specific code does it better, use it", however if what you said is true about the sleep functions, and they do return some time to other processes, then for the purposes of doing exactly nothing for a few to a few trillion clock ticks, using those functions is a better solution than using clock() over and over again until it passes a certain value.
Albatross and Duoas, you are arguing the same point. You're both saying to use [S/s]leep() instead of using clock() but Duoas is saying to create a wrapper function like this: http://www.cplusplus.com/forum/unices/10491/#msg49054
And yes, busywaiting on clock() to return a particular value is a bad idea.