23 TIMERS AND SLEEPING 479 23.1
Interval Timers........................................................................................................... 479
23.2
Scheduling and Accuracy of Timers ............................................................................. 485
23.3
Setting Timeouts on Blocking Operations ...................................................................... 486
23.4
Suspending Execution for a Fixed Interval (Sleeping) ..................................................... 487
23.4.1
Low-Resolution Sleeping:
sleep()
.............................................................. 487
23.4.2
High-Resolution Sleeping:
nanosleep()
...................................................... 488
23.5
POSIX Clocks............................................................................................................ 491
23.5.1
Retrieving the Value of a Clock:
clock_gettime()
........................................ 491
23.5.2
Setting the Value of a Clock:
clock_settime()
............................................. 492
23.5.3
Obtaining the Clock ID of a Specific Process or Thread ............................. 493
23.5.4
Improved High-Resolution Sleeping:
clock_nanosleep()
............................... 493
23.6
POSIX Interval Timers................................................................................................. 495
23.6.1
Creating a Timer:
timer_create()
............................................................. 495
23.6.2
Arming and Disarming a Timer:
timer_settime()
........................................ 498
23.6.3
Retrieving the Current Value of a Timer:
timer_gettime()
............................. 499
23.6.4
Deleting a Timer:
timer_delete()
.............................................................. 499
23.6.5
Notification via a Signal........................................................................ 499
23.6.6
Timer Overruns..................................................................................... 503
23.6.7
Notification via a Thread ....................................................................... 504
23.7
Timers That Notify via File Descriptors: the
timerfd
API ................................................... 507
23.8
Summary.................................................................................................................. 511
23.9
Exercises .................................................................................................................. 512