Training
×

Alarms    

An alarm is an INtime object which is signaled by an event when a given time interval has expired. The alarm mode may be single-shot or repeatable (see dwAlarmFlags). The differences between an alarm and the RtSleep function are:
- RtSleep operates in units of 10 milliseconds, the alarm unit is the system timer tick (default 500 microseconds)
- RtSleep starts to count when the call is executed, an alarm continues counting while the thread may be running.
 
Note that alarms internally are implemented by counting semaphores – an alarm event is a unit sent to the semaphore. Thus, alarm events do accumulate if the associated thread does not immediately work on the next event.
For example, consider that once the alarm event arrived, processing takes longer then expected (most likely because of a weak system layout) and new alarm events are signaled one or more times before your thread executes WaitForRtAlarm (). In this case, the thread will wake up immediately thus trying to catch-up with the alarm events it missed.
The parameter dwMicrosecs in WaitForRtAlarm protects a thread from waiting forever at a single-shot alarm if this thread had missed the only alarm event that can be generated.
Note that any existing alarm objects are deleted automatically at process end.