Classic Problems of Synchronization

classical problems of synchronization

Classic Problems of Synchronization

Classic Problems of Synchronization, We present a number of different synchronization problems as examples for a large class of concurrency-control problems. These problems are used for testing nearly every newly proposed synchronization scheme.Semaphores are used for synchronization in our solutions.

 

The Bounded-Buffer Problem

 

bounded buffer problem

The bounded-buffer problem is commonly used to illustrate the power of synchronization primitives. We present here a general structure of this scheme, without committing ourselves to any particular implementation. We assume that the pool consists of n buffers, each capable of holding one item. The mutex semaphore provides mutual exclusion for accesses to the buffer pool and is initialized to the value 1. The empty and full semaphores count the number of empty and full buffers, respectively. The semaphore empty is initialized to the value n; the semaphore f u l l is initialized to the value 0.

The code for the producer process is

 

do{

produce an item in nextp

wait (empty) ;

wait (mutex) ;

add nextp to buffer

. . .

signal(mutex);

signal (full) ;

) while (1);

 

 

The code for the consumer process is

 

do{

wait (full) ;

wait (mutex) ;

. . .

remove an item from buffer to nextc

signal (mutex) ;

signal (empty) ;

consume the item in nextc

) while (1);

 

Note the symmetry between the producer and the consumer. We can interpret this code as the producer producing full buffers for the consumer, or as the consumer producing empty buffers for the producer.

also read:-The readers writers problem.

also read:-The Dinning philosophers problem.

 

basicittopic

basicittopic

A Computer Science Study for IT students and people of IT community

Leave a Reply

shares