SlideShare a Scribd company logo
1 of 29
PROCESS SYNCHRONIZATION
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).
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.
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
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
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.
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.
• 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
MUTEXBEGIN(gate)
• and an exit protocol denoted by
MUTEXEND (gate).
• 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.
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.
• 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)
• 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 yx;//wait until gate is open //
x1 //set gate to unavailable status //
end
• 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 x1 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.
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.
• 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
• V(s): MUTEXBEGIN (s)
SS + 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
• 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
• 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.
• 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
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;
• 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
• 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
THANK YOU

More Related Content

What's hot

Unit 1 architecture of distributed systems
Unit 1 architecture of distributed systemsUnit 1 architecture of distributed systems
Unit 1 architecture of distributed systems
karan2190
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systems
sumitjain2013
 

What's hot (20)

Unit 1 architecture of distributed systems
Unit 1 architecture of distributed systemsUnit 1 architecture of distributed systems
Unit 1 architecture of distributed systems
 
11. dfs
11. dfs11. dfs
11. dfs
 
Dynamic interconnection networks
Dynamic interconnection networksDynamic interconnection networks
Dynamic interconnection networks
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systems
 
message passing
 message passing message passing
message passing
 
Distributed operating system(os)
Distributed operating system(os)Distributed operating system(os)
Distributed operating system(os)
 
Message passing in Distributed Computing Systems
Message passing in Distributed Computing SystemsMessage passing in Distributed Computing Systems
Message passing in Distributed Computing Systems
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
 
Sequential consistency model
Sequential consistency modelSequential consistency model
Sequential consistency model
 
Unit 2
Unit 2Unit 2
Unit 2
 
System interconnect architecture
System interconnect architectureSystem interconnect architecture
System interconnect architecture
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESSComputer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
 
Distributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithmsDistributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithms
 
Message Passing Systems
Message Passing SystemsMessage Passing Systems
Message Passing Systems
 
Message and Stream Oriented Communication
Message and Stream Oriented CommunicationMessage and Stream Oriented Communication
Message and Stream Oriented Communication
 
Replication in Distributed Systems
Replication in Distributed SystemsReplication in Distributed Systems
Replication in Distributed Systems
 
Monitors
MonitorsMonitors
Monitors
 
Distributed Operating Systems
Distributed Operating SystemsDistributed Operating Systems
Distributed Operating Systems
 

Viewers also liked (8)

Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...
 
Lecture24 Multiprocessor
Lecture24 MultiprocessorLecture24 Multiprocessor
Lecture24 Multiprocessor
 
Multiprocessor Architecture for Image Processing
Multiprocessor Architecture for Image ProcessingMultiprocessor Architecture for Image Processing
Multiprocessor Architecture for Image Processing
 
Multiprocessor Scheduling
Multiprocessor SchedulingMultiprocessor Scheduling
Multiprocessor Scheduling
 
Advanced computer architecture
Advanced computer architectureAdvanced computer architecture
Advanced computer architecture
 
Multiprocessor
MultiprocessorMultiprocessor
Multiprocessor
 
Applications of paralleL processing
Applications of paralleL processingApplications of paralleL processing
Applications of paralleL processing
 
CPU Scheduling - Part2
CPU Scheduling - Part2CPU Scheduling - Part2
CPU Scheduling - Part2
 

Similar to SYNCHRONIZATION IN MULTIPROCESSING

Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
morganjohn3
 
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.pptBIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
Kadri20
 

Similar to SYNCHRONIZATION IN MULTIPROCESSING (20)

IPC
IPCIPC
IPC
 
IPC
IPCIPC
IPC
 
Lecture 5 inter process communication
Lecture 5 inter process communicationLecture 5 inter process communication
Lecture 5 inter process communication
 
Lecture 5 process synchronization
Lecture 5 process synchronizationLecture 5 process synchronization
Lecture 5 process synchronization
 
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
 
Ch5 process synchronization
Ch5   process synchronizationCh5   process synchronization
Ch5 process synchronization
 
slides8 SharedMemory.ppt
slides8 SharedMemory.pptslides8 SharedMemory.ppt
slides8 SharedMemory.ppt
 
Ch4
Ch4Ch4
Ch4
 
Synchronization
SynchronizationSynchronization
Synchronization
 
MODULE IV embedded (1).pptx
MODULE IV embedded (1).pptxMODULE IV embedded (1).pptx
MODULE IV embedded (1).pptx
 
Multiprocessor
MultiprocessorMultiprocessor
Multiprocessor
 
MODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptxMODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptx
 
Intro Basic of OS .ppt
Intro Basic of OS .pptIntro Basic of OS .ppt
Intro Basic of OS .ppt
 
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.pptBIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
 
CHAP4.pptx
CHAP4.pptxCHAP4.pptx
CHAP4.pptx
 
Operating system 23 process synchronization
Operating system 23 process synchronizationOperating system 23 process synchronization
Operating system 23 process synchronization
 
Pipeline and Vector Processing Computer Org. Architecture.pptx
Pipeline and Vector Processing Computer Org. Architecture.pptxPipeline and Vector Processing Computer Org. Architecture.pptx
Pipeline and Vector Processing Computer Org. Architecture.pptx
 
Mumbai MuleSoft Meetup #20
Mumbai MuleSoft Meetup #20Mumbai MuleSoft Meetup #20
Mumbai MuleSoft Meetup #20
 
Ch03 processes
Ch03 processesCh03 processes
Ch03 processes
 
Lecture-4_Process Management.pdf
Lecture-4_Process Management.pdfLecture-4_Process Management.pdf
Lecture-4_Process Management.pdf
 

Recently uploaded

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 

SYNCHRONIZATION IN MULTIPROCESSING

  • 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 yx;//wait until gate is open // x1 //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 x1 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) SS + 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