Chapter 5. Synchronizing Concurrency between Tasks

Chapter 5. Synchronizing Concurrency between Tasks

"The relation of these mechanisms to time demands careful study. ... We are scarcely ever interested in the performance of a communication-engineering machine for a single input. To function adequately, it must give a satisfactory performance for a whole class of inputs, and this means a statistically satisfactory performance for the class of input which it is statistically expected to receive . . ."

Norbert Wiener, Cybernetics

In this Chapter

  • Coordinating Order of Execution

  • Synchronizing Access to Data

  • What are Semaphores?

  • Synchronization: An Object-Oriented Approach

  • Summary

With any computer system, resources are limited. There is only so much memory, I/O devices and ports, hardware interrupts, and processors. In an environment of limited hardware resources, an application consisting of multiple processes and threads must compete for memory locations, peripheral devices, and processor time. It is the job of the operating system to determine when the process or thread utilizes system resources and for how long. With preemptive scheduling, the operating system can interrupt the process or thread in order to accommodate all the processes and threads competing for the system resources. Processes and threads must also compete for software and data resources. An example of software resources is shared libraries that provide a common set of services or functions to processes and threads. Other shareable software resources are applications, programs, and utilities. When sharing software resources, only one copy of the program(s) code is brought into memory. Data resources are objects, system data (e.g., environment variables) files, globally defined variables , and data structures. With data resources, it is possible for processes and threads to have their own copy. In other cases, it is desirable and maybe necessary that data is shared. Some processes and threads work together to use the system's limited resources while other processes and threads work independently and asynchronously, competing for the use of the shareable resource. There are several techniques and mechanisms that can be used by the programmer to manage competing processes and threads to share data resources.

Synchronization is also needed to coordinate the order of execution of concurrent tasks. The producer-consumer model discussed in Chapter 4 is a prime example. It is necessary for the producer to execute before the consumer, not necessarily finish before the consumer. Synchronization is required to coordinate these tasks in order for work to progress. Data ( access synchronization ) and task synchronization ( sequence synchronization ) are two types of synchronization required when executing multiple concurrent tasks.



Parallel and Distributed Programming Using C++
Parallel and Distributed Programming Using C++
ISBN: 0131013769
EAN: 2147483647
Year: 2002
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net