Tickers in Ada
Our example demonstrates the use of tickers in Ada, which are similar to timers but are used for repeating actions at regular intervals. Here’s how we can implement this concept:
In this Ada program, we simulate the behavior of tickers:
We define a protected object
Ticker
to simulate a ticker channel. It has aWait
entry that blocks until the ticker is stopped, and aStop
procedure to stop the ticker.We create a task
Tick_Task
that simulates the periodic ticking. It uses Ada’sdelay until
statement to wait for precise intervals.In the main procedure, we let the ticker run for 1.6 seconds (1600ms) before stopping it.
When we run this program, the ticker should tick approximately 3 times before we stop it. The output might look something like this:
Note that Ada’s timing mechanisms are generally more precise than those in many other languages, so the ticks should occur very close to the specified intervals.
This example demonstrates how to implement periodic actions in Ada, which can be useful for various applications such as updating displays, checking for events, or performing regular maintenance tasks in a program.