2.
3.
There are many ways to provide each of these facilities—but they are always present in some form. The particular choices presented in this book are dictated by the book's subject—Pthreads. Table 1.1 shows a few examples of the three facilities in various systems.
Execution context | Scheduling | Synchronization | |
Real traffic | automobile | traffic lights and signs | turn signals and brake lights |
UNIX | process | priority (nice) | wait and pipes |
(before threads) | |||
Pthreads | thread | policy, priority | condition variables and mutexes |
TABLE 1.1
A system's scheduling facility may allow each thread to run until it voluntarily yields the processor to another thread ("run until block"). It may provide time-slicing, where each thread is forced to periodically yield so that other threads may run ("round-robin"). It may provide various scheduling policies that allow the application to control how each thread is scheduled according to that thread's function. It may provide a "class scheduler" where dependencies between threads are described so that, for example, the scheduler can ensure that members of a tightly coupled parallel algorithm are scheduled at the same time.
Synchronization may be provided using a wide variety of mechanisms. Some of the most common forms are mutexes, condition variables, semaphores, and events. You may also use message passing mechanisms, such as UNIX pipes, sockets, POSIX message queues, or other protocols for communicating between asynchronous processes—on the same system or across a network. Any form of communication protocol contains some form of synchronization, because passing data around with no synchronization results in chaos, not
The terms
1.3 Asynchronous programming is intuitive ...
"In most gardens," the Tiger-lily said,
"they make the beds too soft—so that the flowers are always asleep." This sounded a very good reason, and Alice was quite
pleased to know it. "I never thought of that before!" she said.
If you haven't been involved in traditional realtime programming, asynchronous programming may seem new and different. But you've probably been using
asynchronous programming techniques all along. You've probably used UNIX, for example, and, even as a user, the common UNIX shells from sh to ksh have been designed for asynchronous programming. You've also been using asynchronous "programming" techniques in real life since you were born.
Most people understand asynchronous behavior much more thoroughly than they expect, once they get past the complications of formal and restricted definitions.
1.3.1 ... because UNIX is asynchronous