Published online by Cambridge University Press: 01 June 2011
In Chapter 1 we demonstrated the effectiveness of concurrent algorithms. Together, Horace and Mildred can prepare a meal faster than one of them alone. The concurrent algorithm for controlling the process of chutney cooking provides a simpler and more reusable solution than the original sequential algorithm. Now that you have a basic understanding of sequential programming with Ada we are ready to create concurrent Ada programs.
Ada is a concurrent programming language — it provides the constructs needed to support the creation of programs with multiple threads of control. Ada's task is an implementation of Dijkstra's (1968) process. An Ada program is composed of one or more tasks that execute concurrently to solve a problem. In this chapter we examine the Ada task as an independent entity. In the next two chapters, we'll examine the facilities that allow tasks to communicate, synchronize, and share resources.
Defining tasks
As with packages, the definition of a task has two parts: a declaration and a body. We can define a task type from which we can create multiple tasks that execute the same sequence of statements. Alternatively, we can define a singleton task that ensures that only one task executes the sequence of statements in the body. Let's look at a program that illustrates both alternatives.
To save this book to your Kindle, first ensure [email protected] is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.