I want to perform the above mentioned operation in milliseconds as the unit. Which library and function call should I prefer?
sleep() Function in C. sleep() function in C allows the users to wait for a current thread for a specific time. Other operations of the CPU will function properly but the sleep() function will sleep the present executable for the specified time by the thread.
The sleep() function shall cause the calling thread to be suspended from execution until either the number of realtime seconds specified by the argument seconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process.
Option–Command–Power button* or Option–Command–Media Eject : Put your Mac to sleep. Control–Shift–Power button* or Control–Shift–Media Eject : Put your displays to sleep.
EDIT 2017: C++11 sleep_for
is the right way to do this. Please see Xornad's answer, below.
C++03:
Since Mac OS X is Unix-based, you can almost always just use the standard linux functions!
In this case you can use usleep
(which takes a time in microseconds) and just multiply your milliseconds by 1000 to get microseconds.
#include <unistd.h>
int main () {
usleep(1000); // will sleep for 1 ms
usleep(1); // will sleep for 0.001 ms
usleep(1000000); // will sleep for 1 s
}
For more info on this function, check out the Linux man page:
http://linux.die.net/man/3/usleep
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With