IT IS ABOUT MULTIPROCESSING,COMMUNICATION BETWEEN THE PROCESS THROUGH MESSAGE PASSING AND SHARED MEMORY.SYNCHRONIZATION MECHANISM AND SYNCHRONIZATION USING SEMAPHORE
2. MULTIPROCESSOR SYSTEM
• Multiprocessor System is an interconnection of
2 or more CPU with memory and input-output
equipments.
• Multiprocessors are classified as MIMD
system(Multiple Instruction Multiple Data
Stream).
3. PROCESS
• A process is program in execution.
• A process can be either
– Independent process
– Cooperative process
Independent 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.
4. Cooperative 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
5. Shared Memory
• 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
space.
• The main problem in shared memory is
process synchronization
6.
7. MESSGAE PASSING
• 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
intervention.
• The process will be having separate address
space.
• Process have private memories.
8.
9. PROCESS SYNCHRONIZATION
MECHSNISMS
• 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
accessed.
10. • 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.
11. • 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
MUTEXBEGIN(gate)
• and an exit protocol denoted by
MUTEXEND (gate).
12. • 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.
13. IMPLEMENTATION
LOCK and UNLOCK operations :
• consider that there is a single gate that each
process must pass through to enter a CS and also
leave it.
• 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
locked.
• On completion, the process unlocks the gate and
exits from the CS.
14. • 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:
LOCK (gate)
execute critical section
UNLOCK (gate)
15. • The LOCK(x) operation may be implemented
as follows:
Var x:shared integer;
LOCK (x):begin
var y: integer;
y x;
While y =1 do yx;//wait until gate is open //
x1 //set gate to unavailable status //
end
16. • The UNLOCK(x) operation may be
implemented as
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.
17. • 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.
18. SYNCHRONIZATION WITH
SEMAPHORE
• Dijkstra invented the two operations P and
V, which can be shared by many processes and
which implement the mutual -exclusion
mechanism efficiently.
• 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
critical section.
19. • var s: semaphore
• P(s): MUTEXBEGIN (s)
s s-1;
If s < 0 then
begin
Block the process executing the P(s) and
put it in a FIFO queue associated with the
semaphore s;
end
MUTEXEND
20. • V(s): MUTEXBEGIN (s)
SS + 1;
If s <= 0 then
begin
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.
end
MUTEXEND
21. • When s can take values of 0 or 1, it is called a
binary semaphore.
• If s takes any integer value, it is called a
counting semaphore
22. • 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
queue, respectively.
• The consumer consumes the message from the
head c by updating c and then retrieving the
message.
• The producer adds a message to the buffer by
updating p before the add operation.
23. • 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.
24.
25. • 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.
26. • shared record
begin
var p, c: integer;
var empty, full: semaphore;
var BUFFER [0:n -1]: message;
end
initial empty = n, full = 0, p = 0, c = 0;
27. • Cobegin
Producer: begin
var m: message;
Cycle
begin
Produce a message m;
P(emptv);
p(p+1)modn;
BUFFER [p] m; // place message in buffer//
V(full)
end
end
28. • Consumer: begin
var m: message;
Cycle
begin
P (full);
c(c+1) mod n;
m BUFFER [c]; // remove message from buffer //
V (emptv);
Consume message m;
end
end
coend