Timer Event Semantics

Timer events are perhaps the most well-known type of asynchronous event. To do an operation after a specific time interval has elapsed, a program creates a timer event, and defines a callback function to do the desired operation.

When a program creates a timer event object, the creation call activates the timer event—that is, it requests notification from the operating system when the timer’s interval elapses. When the interval elapses, Rendezvous software places the event object on its event queue. Dispatch removes the event object from the queue, and runs the callback function to process the timer event. On dispatch Rendezvous software also determines whether the next interval has already elapsed, and requeues the timer event if appropriate.

Notice that time waiting in the event queue until dispatch can increase the effective interval of the timer. It is the programmer’s responsibility to ensure timely dispatch of events.

Timer Activation and Dispatch illustrates a sequence of timer intervals. The number of elapsed timer intervals directly determines the number of event callbacks.

At any moment the timer object appears on the event queue only once—not several times as multiple copies. Nonetheless, Rendezvous software arranges for the appropriate number of timer event callbacks based the number of intervals that have elapsed since the timer became active or reset its interval.

Destroying or invalidating the timer object immediately halts the sequence of timer events. The timer object ceases to queue new events, and an event already in the queue does not result in a callback. (However, callback functions that are already running in other threads continue to completion.)

A timer repeats indefinitely—until the program destroys the timer event object.

Resetting the timer interval immediately interrupts the sequence of timer events and begins a new sequence, counting the new interval from that moment. The reset operation is equivalent to destroying the timer and creating a new object in its place.

Figure 24: Timer Activation and Dispatch

Timer Creation

C

tibrvEvent_CreateTimer()

C++

TibrvTimer::create()

Java

TibrvTimer()

.NET

Timer events are not available with .NET.