next up previous contents index
Next: Command Protocol Up: Interprocess communication Previous: Interprocess communication   Contents   Index


Synchronization Primitives

The low-level synchronization of access to shared resources is done with mutexes and condition variables which are implemented via semaphores.

class Mutex {
public:
  void Lock();
  void Unlock();
  // ...
};

Typically a mutex guards some resource, such as memory buffers. To make sure that only one process at a time accesses the shared resource, processes are expected to lock the mutex before touching the resource and unlock it when they are done.

class CondVar {
public:
  void Wait ( Mutex & );
  void Signal();
  // ...
};
Whereas a mutex allows processes to synchronize by controlling their access to data, a condition variable allows processes to synchronize on the value of data. Cooperating processes wait until data reaches some particular state or until some particular event occurs. To release processes that are waiting on a condition variable, a process calls the Signal() function which wakes up only one of the potentially many processes waiting on the condition.



Alexander V.Inyakin 2002-04-05