Computer Science Engineering (CSE)  >  OPERATING SYSTEMS : Process Synchronization

OPERATING SYSTEMS : Process Synchronization - Notes - Computer Science Engineering (CSE)

Download, print and study this document offline
 Page 1


6: Process Synchronization 
1 
Jerry Breecher 
OPERATING SYSTEMS  
 
PROCESS SYNCHRONIZATION 
Page 2


6: Process Synchronization 
1 
Jerry Breecher 
OPERATING SYSTEMS  
 
PROCESS SYNCHRONIZATION 
6: Process Synchronization 
2 
What Is In This Chapter? 
 
• This is about getting processes to coordinate with each other. 
 
• How  do processes work with resources that must be shared 
between them? 
 
• How  do we go about acquiring locks to protect regions of memory? 
 
• How is synchronization really used? 
OPERATING SYSTEM 
Synchronization 
Page 3


6: Process Synchronization 
1 
Jerry Breecher 
OPERATING SYSTEMS  
 
PROCESS SYNCHRONIZATION 
6: Process Synchronization 
2 
What Is In This Chapter? 
 
• This is about getting processes to coordinate with each other. 
 
• How  do processes work with resources that must be shared 
between them? 
 
• How  do we go about acquiring locks to protect regions of memory? 
 
• How is synchronization really used? 
OPERATING SYSTEM 
Synchronization 
6: Process Synchronization 
3 
Topics Covered 
 
• Background 
• The Critical-Section Problem 
• Peterson’s Solution 
• Synchronization Hardware 
• Semaphores 
• Classic Problems of Synchronization 
• Synchronization Examples  
• Atomic Transactions 
OPERATING SYSTEM 
Synchronization 
Page 4


6: Process Synchronization 
1 
Jerry Breecher 
OPERATING SYSTEMS  
 
PROCESS SYNCHRONIZATION 
6: Process Synchronization 
2 
What Is In This Chapter? 
 
• This is about getting processes to coordinate with each other. 
 
• How  do processes work with resources that must be shared 
between them? 
 
• How  do we go about acquiring locks to protect regions of memory? 
 
• How is synchronization really used? 
OPERATING SYSTEM 
Synchronization 
6: Process Synchronization 
3 
Topics Covered 
 
• Background 
• The Critical-Section Problem 
• Peterson’s Solution 
• Synchronization Hardware 
• Semaphores 
• Classic Problems of Synchronization 
• Synchronization Examples  
• Atomic Transactions 
OPERATING SYSTEM 
Synchronization 
6: Process Synchronization 
4 
PROCESS 
SYNCHRONIZATION 
A producer process "produces" information "consumed" by a consumer process. 
Here are the variables needed to define the problem: 
  
The Producer 
Consumer Problem 
#define BUFFER_SIZE 10 
typedef struct { 
    DATA  data; 
} item; 
item  buffer[BUFFER_SIZE]; 
int  in = 0;  // Location of next input to buffer 
int  out = 0;  // Location of next removal from buffer 
int    counter = 0;           // Number of buffers currently full 
Consider the code segments on the next page: 
 
• Does it work? 
• Are all buffers utilized? 
 
Page 5


6: Process Synchronization 
1 
Jerry Breecher 
OPERATING SYSTEMS  
 
PROCESS SYNCHRONIZATION 
6: Process Synchronization 
2 
What Is In This Chapter? 
 
• This is about getting processes to coordinate with each other. 
 
• How  do processes work with resources that must be shared 
between them? 
 
• How  do we go about acquiring locks to protect regions of memory? 
 
• How is synchronization really used? 
OPERATING SYSTEM 
Synchronization 
6: Process Synchronization 
3 
Topics Covered 
 
• Background 
• The Critical-Section Problem 
• Peterson’s Solution 
• Synchronization Hardware 
• Semaphores 
• Classic Problems of Synchronization 
• Synchronization Examples  
• Atomic Transactions 
OPERATING SYSTEM 
Synchronization 
6: Process Synchronization 
4 
PROCESS 
SYNCHRONIZATION 
A producer process "produces" information "consumed" by a consumer process. 
Here are the variables needed to define the problem: 
  
The Producer 
Consumer Problem 
#define BUFFER_SIZE 10 
typedef struct { 
    DATA  data; 
} item; 
item  buffer[BUFFER_SIZE]; 
int  in = 0;  // Location of next input to buffer 
int  out = 0;  // Location of next removal from buffer 
int    counter = 0;           // Number of buffers currently full 
Consider the code segments on the next page: 
 
• Does it work? 
• Are all buffers utilized? 
 
6: Process Synchronization 
5 
PROCESS 
SYNCHRONIZATION 
A producer process "produces" information 
"consumed" by a consumer process. 
  
The Producer 
Consumer Problem 
item   nextProduced; 
 
while (TRUE) { 
while (counter == BUFFER_SIZE); 
buffer[in] = nextProduced; 
in = (in + 1) % BUFFER_SIZE; 
counter++; 
} 
item  nextConsumed; 
 
while (TRUE) { 
while (counter == 0); 
nextConsumed = buffer[out]; 
out = (out + 1) % 
BUFFER_SIZE; 
counter--; 
} 
#define BUFFER_SIZE 10 
typedef struct { 
    DATA data; 
} item; 
item  buffer[BUFFER_SIZE]; 
int  in = 0;   
int  out = 0; 
int     counter = 0; 
PRODUCER 
CONSUMER 
producer consumer 
Read More
Download as PDF

Download free EduRev App

Track your progress, build streaks, highlight & save important lessons and more!

Related Searches

Extra Questions

,

ppt

,

Exam

,

Previous Year Questions with Solutions

,

pdf

,

Semester Notes

,

video lectures

,

MCQs

,

Summary

,

mock tests for examination

,

Sample Paper

,

Objective type Questions

,

shortcuts and tricks

,

OPERATING SYSTEMS : Process Synchronization - Notes - Computer Science Engineering (CSE)

,

past year papers

,

study material

,

practice quizzes

,

Viva Questions

,

Important questions

,

OPERATING SYSTEMS : Process Synchronization - Notes - Computer Science Engineering (CSE)

,

OPERATING SYSTEMS : Process Synchronization - Notes - Computer Science Engineering (CSE)

,

Free

;