Synchronization API
In this section we go over the common API used for
synchronization. Not all API are available on all operating systems and
libraries. The section covers the majority of common API as a general concept
with little reference to specific library implementation and parameters.
The API can be grouped into several sets as follows:
Task
The task API set deals with creation and destruction of tasks which means
Processes, Threads, Fibers, and so on.
Wait
Today the majority of operating systems and libraries use Wait API for
synchronization. A task can wait for something to happen and while it is waiting
it will not waste CPU time. It is possible to wait for a MUTEX to release, an
Event to happen, a Semaphore, etc.
Lock
Lock is a core element of synchronization today. We use this API set to
synchronize access to resources in code. Only one Task can own the locking
element and all other Tasks can wait for it. These include MUTEX object,
Critical Sections etc.
Event
Every parallel system reacts to events. Events are basic elements of
interruptible systems. Tasks wait on Events that other Tasks can signal.
Software events in an interruptible system are called Events. Hardware events in
an interruptible system are called Interrupts.
Count
The majority of libraries also include an implementation of a counter. This API
is usually called Semaphore and can either count to a limit or unlimited
depending on the library.
Timer
A Timer is also a synchronization element because it allows synchronous
operations periodically. There are timers that can send an event and there are
timers that can block a Task that it waiting until the time has elapsed.
Atomic Operations
Most high level CPUs support Read-Modify-Write sequences in a single op-codes
(represented as a single Assembly instruction). The CPU cannot perform a Context
Switch during an op-code so this is considered thread safe. These op-codes
represented in high level API are called Atomic Operations.