Timers
Kernel API provides two kinds of interruptions: one-time and periodic. one-time interruption is always synchronous - the thread won’t be given control until delay elapses. Kernel is free to schedule any other thread in this time if delay is long enough.
Periodic delays are always asynchronous - the thread won’t be stopped after the delay is scheduled. Once the delay elapses, kernel will deliver a signal to the requesting thread. If thread has nothing to do until the delay elapses, it may stop itself via calling kill()
Function-like Macros
int usleep(unsigned microseconds)
Suspends thread execution for given amount of time. After this amount of time elapses, thread execution is resumed. Suspend is one-time and usleep()
microseconds amount of microseconds (1/100000 s) to sleep Actual amount of time which thread will be suspended depends on system tick granularity and status of scheduler at the time of wake-up. If there is another thread running/ready with equal/higher priority, then actual wake-up may be delayed by the time consumed by this high-priority thread.
- microseconds amount of microseconds (1/100000 s) to sleep
int setitimer(unsigned microseconds)
Configures interval timer, which will periodically be called, until cancelled. Timer is called by delivering the SIGTIMER signal to the thread. If thread is stopped, then SIGTIMER will resume it and call signal handler. If there is no signal handler configured, then thread will just be resumed.
microseconds period of timer signals received. If set to 0, then interval timer is cancelled.
- microseconds period of timer signals received. If set to 0, then interval timer is cancelled.