• Multiprocessor System is an interconnection of
2 or more CPU with memory and input-output
• Multiprocessors are classified as MIMD
system(Multiple Instruction Multiple Data
• A process is program in execution.
• A process can be either
– Independent process
– Cooperative process
– A process is independent if it is not affected by
other process executing in the system.
– Process will not share data with other process.
– A process can affect or be affected by other
process executing in the system.
– Process share data with other process.
• Cooperative process requires interprocess
communication(IPC) mechanism to exchange
data and information.
• 2 fundamental models:
– Shared memory
– Message massing
• A region of memory that is shared by
cooperative process is established .
• Process can exchange information by reading
and writing to shared memory.
• It allows maximum speed.
• Processor communicates with shared address
• The main problem in shared memory is
• Communication takes place by means of message
exchange between cooperating process.
• It is useful for exchanging smaller amount of data.
• It is time consuming as there is kernel
• The process will be having separate address
• Process have private memories.
• Mainly 2 types of synchronizations are used:
– Mutual exclusion
– Condition synchronization
• Mutual Exclusion: If a process is executing
its critical section then no other process can
execute in their critical section.
– A critical section is a piece of code that accesses a
shared resource that must not be concurrently
• Condition synchronization:
– When a shared data object is in a state that is
inappropriate for executing a given operation.
– Any process which attempt such an operation
should be delayed until the state of the data object
changes to the desired value as a result of other
process being executed.
• The mutual -exclusive execution of a critical
section,S,whose access is controlled by a
variable gate can be enforced by :
• an entry protocol denoted by
• and an exit protocol denoted by
• Execution of the MUTEXBEGIN statement
should detect the status of the critical section.
• If it is busy, the process attempting to enter
the critical section must wait.
• Execution of the MUTEXEND statement
should reset the status of the critical section to
idle and provide a mechanism to schedule the
waiting process to use the critical section.
LOCK and UNLOCK operations :
• consider that there is a single gate that each
process must pass through to enter a CS and also
• If a process attempting to enter the CS finds the
gate unlocked (open) it locks (closes) it as it
enters the CS so that all other processes
attempting to enter the CS will find the gate
• On completion, the process unlocks the gate and
exits from the CS.
• Assuming that the variable
• gate =0 means that the gate is open
• gate=1 means that the gate is closed,
• the access to a CS controlled by the gate can
be written as:
execute critical section
• The LOCK(x) operation may be implemented
Var x:shared integer;
var y: integer;
While y =1 do yx;//wait until gate is open //
x1 //set gate to unavailable status //
• The UNLOCK(x) operation may be
UNLOCK(x): x 0;
DISADVANTAGE OF LOCK MECHANISM:
• two or more processes may find x=0 before
one reaches the x1 statement.
• processes attempting to enter critical sections
are busy accessing common variables.
• This is called busy –wait or spin -lock, which
results in performance degradation.
• An important property of locks is that :
• a process does not relinquish the processor on
which it is executing while it is waiting for a
lock held by another process.
• Thus, it is able to resume execution very
quickly when the lock becomes available.
• Dijkstra invented the two operations P and
V, which can be shared by many processes and
which implement the mutual -exclusion
• The P and V operations are called primitives .
• They operate on a special common variable
called a semaphore, which indicates the
number of processes attempting to use the
• var s: semaphore
• P(s): MUTEXBEGIN (s)
If s < 0 then
Block the process executing the P(s) and
put it in a FIFO queue associated with the
• V(s): MUTEXBEGIN (s)
SS + 1;
If s <= 0 then
if an inactive process associated with
semaphore s exists, then wake up the highest
priority blocked process associated with s and
put it in a ready list.
• When s can take values of 0 or 1, it is called a
• If s takes any integer value, it is called a
• Eg.Producer Consumer Problem
• consider a finite buffer BUFFER of size n
arranged as a circular queue in which the slot
positions are named 0, 1,…., n-1.
• There are the two pointers c and p, which
correspond to the "head" and "tail" of a circular
• The consumer consumes the message from the
head c by updating c and then retrieving the
• The producer adds a message to the buffer by
updating p before the add operation.
• Initially, p= c = 0, which indicates that the
buffer is empty.
• Let the variables empty and full be used to
indicate the number of empty slots and
occupied slots, respectively.
• The empty variable is used to inform the
producer of the number of available slots.
• the full• variable informs the consumer of the
number of messages needed to be consumed.
• The producer or consumer will be suspended
when empty=0 or full = 0, respectively.
• shared record
var p, c: integer;
var empty, full: semaphore;
var BUFFER [0:n -1]: message;
initial empty = n, full = 0, p = 0, c = 0;
var m: message;
Produce a message m;
BUFFER [p] m; // place message in buffer//
• Consumer: begin
var m: message;
c(c+1) mod n;
m BUFFER [c]; // remove message from buffer //
Consume message m;