Summary
Chapter 20 covered the basic concepts concerning tasking. This chapter provides a number of further examples of tasks and protected objects in order to illustrate how the various facilities work together.
An important topic which was only briefly alluded to earlier is the use of synchronized interfaces which pull together two very important features of programming namely OOP and concurrency.
Some topics covered in this chapter are in fact defined in the Systems Programming or Real-Time Systems annexes and thus might not be available in all implementations. However, they seem worthy of more detail than would otherwise be given in the brief notes on the specialized annexes in Chapter 26.
Dynamic tasks
The first example is an interesting demonstration of the dynamic creation of task objects. The objective is to find and display the first few prime numbers using the Sieve of Eratosthenes. (Eratosthenes was a Greek mathematician in the 3rd century BC and a friend of Archimedes of Eureka fame.) This ancient algorithm works using the observation that if we have a list of the primes below N, then N is also prime if none of these divide exactly into it. So we try the existing primes in turn and as soon as one divides N we discard N and try again with N set to N+1. If we get to the end of the list of primes without dividing N, then N must be prime, so we add it to the list and start again with N+1.
- Type
- Chapter
- Information
- Programming in Ada 2012 , pp. 587 - 626Publisher: Cambridge University PressPrint publication year: 2014