Our primary mechanism for managing state in Ada is through protected objects. However, there are other options for managing state. Here we’ll look at using Ada’s atomic operations for atomic counters accessed by multiple tasks.
We expect to get exactly 50,000 operations. Had we used a non-atomic integer and incremented it with regular addition, we’d likely get a different number, changing between runs, because the tasks would interfere with each other. Moreover, we’d get race conditions that could lead to unpredictable behavior.
To compile and run this Ada program:
Next, we’ll look at protected objects, another tool for managing state in Ada.