SlideShare a Scribd company logo
Process Synchronization
Presented by Dani Mfungo
HD/UDOM/408/T.2015
CS603:computer system programming
Objective and Outcomes
• What happened when Concurrent process shared data
• How to handle data inconsistency
• Investigate a critical section (CS) as a protocol for synchronization
• Algorithmic approach to CS implementation
• Investigate classical process-synchronization problems
• Producer – consumer problem
• Dining –philosopher problems
• Sleeping barber problems
• Cigarette smokers’ problem
• Investigation of tools used to solve process synchronization problems
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Lets consider to approach on handling concurrent
problem
• LANGUAGE STRUCTURE FOR CONCURENCY PROCESS
• Fork – Join
• Cobegin - Coend
• How do they help on construct concurrency program??
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
TRANSLATE THE PRECENDENCE GRAPH TO
Cobegin –Coend structure
1. Begin
2. S1;
3. Cobegin
4. S3;
5. begin
6. S2;
7. Cobegin
8. S4;
9. S5;
10. Coend
11. S6;
12. End
13. Coend
14. S7;
15. End Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
TRANSLATE THE PRECENDENCE GRAPH TO
fork –join structure
1. Begin L1:S3 L2:S6
2. count = 3; goto L3 goto L3
3. S1;
4. fork L1
5. S2;
6. S4;
7. fork L2
8. S5;
9. L3: join count;
10. S7;
11. End
Task of Join Count statement
Count = count -1
If count ≠ 0 𝑡ℎ𝑒𝑛 𝑄𝑢𝑖𝑡
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Which structure is better than Other?
What is solution for a system which
implement
Cobegin – Coend structure ???
• It is impossible to write Cobegin – Coend Here
• Fork –join is the best solution
? Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
PRODUCER / CONSUMER PROBLEM
What will happen if
• the rate to producer is greater than the rate to consume?
• Rate to producer < rate to consume?
• Rate to produce == to Rate to consume?
• Producer generate Items
• Consumer consume item
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
PRODUCER – CONSUMER PROBLEM-> SOLUTION
Two Situation
1. Unbounded Buffer
2. Bounded buffer – limited size
When buffer is buffer is full,
• producer wait until items are consumed
• Rate of consumption > rate of production, result to empty buffer
Producer Consumer problems also known as Bounded Buffer Problem
Buffer (n)
P
c
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
bounded buffer problem
• Solution to this must satisfy the following condition
1. A producer must not overwrite a full buffer
2. Consumer must not consume an empty buffer
3. Consumer and buffer must access buffer in a mutually exclusive manner
• Variable count keep track number of item (N) in buffer
• For Producer
• If count = n -> buffer is full then producer go to sleep
• If count ≠ 𝑛 producer add item and increment count
• For Consumer
• If count = 0 - > buffer empty, consumer go to sleep
• If count ≠ 0 consumer remove an item and decrement counter
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
bounded buffer problem
Is this simple algorithm free of problems??
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Producer Process
count + 1
A: R1 = count
B: R1 = R1+ 1
C: count = R1
Consumer Process
count -1
D: R2 = count
E: R2 = R2-1
F: count = R2
Bounded buffer weakness & race condition
Execution sequence
A R1 =7
B R1=8
D R2=7
E R2=6
C count=8
F count=6
 Also consider Transaction process
 Race condition result a critical
section problems
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
CRITICAL SECTION
• A critical section of a data item d is a section of code which cannot be executed
concurrently with it self or with other critical section(s) for d.
• PROPERTIES OF CS IMPLEMENTATION
• CORRECTENESS (Mutual execution): at most one process may execute a CS at a given
moment
• PROGRESS: A process will take a finite time interval to execute its critical section
• BOUNDED WAIT: Processes wait a finite time interval to enter their critical
sections.
• Absence of deadlock: Processes should not block each other indefinitely
Sunday, July 10, 2016DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Approaches for Implementing Synchronization
• 3 Categories
1. Busy waiting
2. Hardware support
3. Operating System support
1. Dekker’s algorithm and Peterson’s algorithm are used for Busy waiting
2. Disable interrupt for accessing hardware facilities
3. Mechanism and tools such as semaphores and monitors are used by OS
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
CRITICAL SECTION
• Entry section make decision if process should enter CS or not
• Shared Lock mechanism is used for CS
• Process enter a exit section after CS
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
ENTRY SECTION {
} EXIT SECTION {
CRITICAL SECTION
REMINDER SECTION
}
Decision made, locking mechanism
Decision made, locking mechanism (unlock process)
Reminder section (other part of the code)
Simple natural solution
• Synchronization between two process P1 and P2
• Each process wait for the other to leave CS
• Implement shared variable process_turn
• While loop act as entry section and if variable = 1, P1 enter CS otherwise if 2, P2
enter CS
• P1 finish execution, initialize process_turn to 2, P2 execute also.
• What if P2 still in non critical section and don’t want to execute?
• This approach / protocol will satisfy ME but not Progress
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
• Only Mutual execution are granted
• Progress is not work in this situation
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Another Solution
• The algorithm is that it does not save the state of the executing process
• To store the state of the process, two more variables, namely, state_flag_P1 and
state_flag_P2
• If a process enters its critical section, it first sets this state flag to zero,
and after exiting, it sets it to one
• It indicates that if a process is using its CS, then the other process must wait until the state
flag becomes one,
• state flag variables eliminate the problem of progress
• Also this solution suffer from other problem as well – don’t guarantee Mutual execution
since
• In the beginning, when no process is executing, both P1 and P2 will try to enter the critical
section
consider diagram
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
3rd Solution
• Setting state_flag_P1 and state_flag_P2 to 0 before the while loop
• This will solve the problem of mutual exclusion, but there still is one problem
• Suppose, at the moment P1 starts and executes its first statement as state_ flag_P1 =
0, P2 interrupts and gets the execution and executes its first statement, state_ flag_P2
= 0.
• In this situation, if P2 continues and executes its while loop, then it will not be able to
proceed as it is waiting for P1 to set state_ flag_P1 to 1.
• Both the processes are waiting for each other, thereby causing deadlock in the
system.
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
• Two result
• Dead lock and livelock
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Dekker’s Solution
• This algorithm satisfies all the rules of the designed protocol.
• Both the processes will not try to enter simultaneously due to the variable,
process_turn and will satisfy the mutual exclusion property.
• If P1 starts first and finds that state_ flag_P2 = 0, that is, P2 wants to enter the CS, it
will allow P2, only when process_turn = 2.
• Otherwise, it will wait for state_ flag_P2 to be 1 so that P1 can enter its CS. If state_
flag_P2 = 1 initially, then P1 will skip the while loop and straightway enter the CS.
• In this way, there will not be any deadlock or livelock.
• Moreover, the chance is given to only those processes that are waiting in the queue
to enter the CS.
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Dekker’s Solution
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Peterson’s Solution
• easier method compared to Dekker’s solution
var flag: array [0..1] of Boolean;
Turn : 0..1;
Pi
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Flag [i] =true;
Turn =j;
While(flag[i] and turn=j) do skip;
CS
Flag [i] = false;
• process_turn takes the value zero for Process P1 and one for Process P2
• For the process flag, a Boolean array process_ flag[] is taken that consists
of two values, 0 for P1 and 1 for P2
• The variable process_turn maintains the mutual exclusion and process_ flag[]
maintains the state of the process.
• Initially, both the processes make their flags true but to maintain the mutual
exclusion, the processes before entering their critical sections allow other
processes to run
• After exiting the critical section, the process makes its flag false so that the
other process can start if it wants.
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Peterson’s Solution
SEMAPHORE
• The semaphore is used to protect any resource such as global shared memory that needs to be
accessed and updated by many processes simultaneously
• Semaphore acts as a guard or lock on the resource
• Whenever a process needs to access the resource, it first needs to take permission from the
semaphore
• The semaphore is implemented as an integer variable, say as S, and can be initialized with any
positive integer values.
• The semaphore is accessed by only two indivisible operations known as wait and signal
operations, denoted by P and V, respectively
• Whenever a process tries to enter the critical section, it needs to perform wait operation
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
SEMAPHORE cont…
• Initially, the count of semaphore is 1
• It decrement to zero when process accesses the available critical area
• When a process exits the critical section, it performs the signal operation
• The semaphore whose value is either zero or one is known as binary semaphore
• semaphore that takes a value greater than one is known as counting semaphore.
• In binary semaphore,the CS locked by a process may be unlocked by any other
process.
• However, in mutex, only the process that locks the CS can unlock it.
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
one problem in the implementation of such a semaphore
• When a process does not get access to the critical
section, it loops continually waiting for it.
• This does not produce any result but consumes CPU
cycles, thereby wasting the processor time
Mutex: semaphore mutex=1
Pi: P(mutex)
CS
V(mutex)
RS
SOLUTION OF CLASSIC SYNCHRONIZATION PROBLEMS
USING SEMAPHORES
• PROCESS SYNCHRONIZATION
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
P(sync)
Sj
Si
V(sync)
Si Sj
Sync:semaphore
Sync = 0;
S1
S2
.
.
.
Si
Si+1
Si+2
.
.
U1
U2
.
.
.
Uj
Uj+1
Uj+2
.
.
V(s)
P(s)
Wait for Ui to finish
Sequence: J1 J2
Run
concurrently
SOLUTION OF CLASSIC SYNCHRONIZATION PROBLEMS USING
SEMAPHORES
• SOLUTION OF Cobegin – coend synchronization process
Variable a,b,c,d,e,g: semaphore
1. Begin
2. Cobegin
3. S1; V(a);V(b); end
4. P(a); S2;S4;V(c);V(d);
5. P(b); S3; V(e);
6. P(c);S5;V(f);
7. P(d);P(e);S6;V(g);
8. P(f);P(g);S7;
9. coend
10. End
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Type semaphore = record
value= integer;
L: list of processes;
end;
Var S:semaphore;
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
TO OVERCOME A BUSY WAIT PROBLEM
Define a semaphore AS structure or records and not integer
V(S): S.Value=S.Value+1
If S.value ≤ 0 then
Begin
Remove process P from S.L
//put P into ready queue
Wakeup(P);
End;
P(S): S.Value=S.Value-1
If S.value<0 then
Begin
Add this process to S.L
// into wait state
Block;
End;
SOLUTION OF CLASSIC SYNCHRONIZATION PROBLEMS USING
SEMAPHORES
• PRODUCER/ CONSUMER PROBLEM
full,empty,mutex:semaphore
nextp, nextc:item
full =0;
empty=n;
mutex=1;
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015
Consumer:
repeat
P(full)
P(mutex)
……
Remove an item from buffer to nextc
……
V(mutex)
V(empty)
Until false;
Producer:
repeat
production on item in nextp;
…..
P(empty)
P(mutex)
……
Add nextp to buffer
……
V(mutex)
V(full)
Until false;
CONSUMERPRODUCER
Demostration
Simulation about Process synchronization
Sunday, July 10,
2016
DANI ELIAS MFUNGO HD/UDOM/408/T.2015

More Related Content

What's hot

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
SHIKHA GAUTAM
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
Harshana Madusanka Jayamaha
 
Bankers
BankersBankers
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
Ra'Fat Al-Msie'deen
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Ravindra Raju Kolahalam
 
Dining Philosopher Problem
Dining Philosopher ProblemDining Philosopher Problem
Dining Philosopher Problem
Raval Vijay
 
Dining philosopher problem operating system
Dining philosopher problem operating system Dining philosopher problem operating system
Dining philosopher problem operating system
anushkashastri
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationWayne Jones Jnr
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronization
cscarcas
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
Syed Hassan Ali
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
Mukesh Chinta
 
Distributed Operating System_3
Distributed Operating System_3Distributed Operating System_3
Distributed Operating System_3
Dr Sandeep Kumar Poonia
 
5 process synchronization
5 process synchronization5 process synchronization
5 process synchronization
BaliThorat1
 
Threads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationThreads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess Communication
Shivam Mitra
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
Adeel Rasheed
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock Detection
SHIKHA GAUTAM
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
Bipul Chandra Kar
 
Synchronization
SynchronizationSynchronization
SynchronizationMohd Arif
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
Pritom Saha Akash
 

What's hot (20)

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Bankers
BankersBankers
Bankers
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
Dining Philosopher Problem
Dining Philosopher ProblemDining Philosopher Problem
Dining Philosopher Problem
 
Dining philosopher problem operating system
Dining philosopher problem operating system Dining philosopher problem operating system
Dining philosopher problem operating system
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronization
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
 
Distributed Operating System_3
Distributed Operating System_3Distributed Operating System_3
Distributed Operating System_3
 
5 process synchronization
5 process synchronization5 process synchronization
5 process synchronization
 
Threads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationThreads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess Communication
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock Detection
 
SYNCHRONIZATION
SYNCHRONIZATIONSYNCHRONIZATION
SYNCHRONIZATION
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
 

Viewers also liked

Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
Anas Ebrahim
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmSouvik Roy
 
Web technology
Web technologyWeb technology
Web technology
Selvin Josy Bai Somu
 
Operating Systems - Synchronization
Operating Systems - SynchronizationOperating Systems - Synchronization
Operating Systems - Synchronization
Emery Berger
 
Web Tech
Web TechWeb Tech
Web Tech
Rupsee
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
sgpraju
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlockstech2click
 
Soft computing
Soft computingSoft computing
Soft computing
Dr Sandeep Kumar Poonia
 

Viewers also liked (8)

Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's Algorithm
 
Web technology
Web technologyWeb technology
Web technology
 
Operating Systems - Synchronization
Operating Systems - SynchronizationOperating Systems - Synchronization
Operating Systems - Synchronization
 
Web Tech
Web TechWeb Tech
Web Tech
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
Soft computing
Soft computingSoft computing
Soft computing
 

Similar to Process synchronization in operating system

Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdf
Amanuelmergia
 
Mule soft meetup__adelaide_october_2020_final (2)
Mule soft meetup__adelaide_october_2020_final (2)Mule soft meetup__adelaide_october_2020_final (2)
Mule soft meetup__adelaide_october_2020_final (2)
Nicholas Bowman
 
What's New? - February 2017
What's New? - February 2017What's New? - February 2017
What's New? - February 2017
Lizzy Guido (she/her)
 
Simplifying debugging for multi-core Linux devices and low-power Linux clusters
Simplifying debugging for multi-core Linux devices and low-power Linux clusters Simplifying debugging for multi-core Linux devices and low-power Linux clusters
Simplifying debugging for multi-core Linux devices and low-power Linux clusters
Rogue Wave Software
 
Hybrid Automation Framework Developement
Hybrid Automation Framework DevelopementHybrid Automation Framework Developement
Hybrid Automation Framework DevelopementGlasdon Falcao
 
Ask the Experts: SDL Trados live Q+A webinar for freelance translators
Ask the Experts: SDL Trados live Q+A webinar  for freelance translatorsAsk the Experts: SDL Trados live Q+A webinar  for freelance translators
Ask the Experts: SDL Trados live Q+A webinar for freelance translators
Paul Filkin
 
Stop the Line practice in SW development
Stop the Line practice in SW developmentStop the Line practice in SW development
Stop the Line practice in SW development
Gabor Gunyho
 
From Waterfall to Weekly Releases: A Case Study in using Evo and Kanban (2004...
From Waterfall to Weekly Releases: A Case Study in using Evo and Kanban (2004...From Waterfall to Weekly Releases: A Case Study in using Evo and Kanban (2004...
From Waterfall to Weekly Releases: A Case Study in using Evo and Kanban (2004...
Tathagat Varma
 
Stop the line & Stop Feature Development practices
Stop the line & Stop Feature Development practicesStop the line & Stop Feature Development practices
Stop the line & Stop Feature Development practices
Agile Spain
 
TuleapCon 2017-STMicroelectronics-Case-Study
TuleapCon 2017-STMicroelectronics-Case-StudyTuleapCon 2017-STMicroelectronics-Case-Study
TuleapCon 2017-STMicroelectronics-Case-Study
Tuleap
 
Moving towards a more efficient and flexible delivery model in automotive env...
Moving towards a more efficient and flexible delivery model in automotive env...Moving towards a more efficient and flexible delivery model in automotive env...
Moving towards a more efficient and flexible delivery model in automotive env...
Agustin Benito Bethencourt
 
Why Test SAP PI/PO after any upgrade
Why Test SAP PI/PO after any upgradeWhy Test SAP PI/PO after any upgrade
Why Test SAP PI/PO after any upgrade
Daniel Graversen
 
Tackling Terraform at Ticketmaster
Tackling Terraform at TicketmasterTackling Terraform at Ticketmaster
Tackling Terraform at Ticketmaster
Fastly
 
FAPI / Open Banking Conformance #fapisum - Japan/UK Open Banking and APIs Sum...
FAPI / Open Banking Conformance #fapisum - Japan/UK Open Banking and APIs Sum...FAPI / Open Banking Conformance #fapisum - Japan/UK Open Banking and APIs Sum...
FAPI / Open Banking Conformance #fapisum - Japan/UK Open Banking and APIs Sum...
FinTechLabs.io
 
A brief history of automation in Software Engineering
A brief history of automation in Software EngineeringA brief history of automation in Software Engineering
A brief history of automation in Software Engineering
Georg Buske
 
The Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security TestingThe Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security Testing
Matt Tesauro
 
meetup version of Paving the road to production
  meetup version of Paving the road to production    meetup version of Paving the road to production
meetup version of Paving the road to production
Matthew Reynolds
 
TuleapCon 2017-STMicroelectronics-Imaging-Division-Case-Study
TuleapCon 2017-STMicroelectronics-Imaging-Division-Case-StudyTuleapCon 2017-STMicroelectronics-Imaging-Division-Case-Study
TuleapCon 2017-STMicroelectronics-Imaging-Division-Case-Study
Tuleap
 

Similar to Process synchronization in operating system (20)

Ipc feb4
Ipc feb4Ipc feb4
Ipc feb4
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdf
 
Mule soft meetup__adelaide_october_2020_final (2)
Mule soft meetup__adelaide_october_2020_final (2)Mule soft meetup__adelaide_october_2020_final (2)
Mule soft meetup__adelaide_october_2020_final (2)
 
What's New? - February 2017
What's New? - February 2017What's New? - February 2017
What's New? - February 2017
 
Shared Memory
Shared MemoryShared Memory
Shared Memory
 
Simplifying debugging for multi-core Linux devices and low-power Linux clusters
Simplifying debugging for multi-core Linux devices and low-power Linux clusters Simplifying debugging for multi-core Linux devices and low-power Linux clusters
Simplifying debugging for multi-core Linux devices and low-power Linux clusters
 
Hybrid Automation Framework Developement
Hybrid Automation Framework DevelopementHybrid Automation Framework Developement
Hybrid Automation Framework Developement
 
Ask the Experts: SDL Trados live Q+A webinar for freelance translators
Ask the Experts: SDL Trados live Q+A webinar  for freelance translatorsAsk the Experts: SDL Trados live Q+A webinar  for freelance translators
Ask the Experts: SDL Trados live Q+A webinar for freelance translators
 
Stop the Line practice in SW development
Stop the Line practice in SW developmentStop the Line practice in SW development
Stop the Line practice in SW development
 
From Waterfall to Weekly Releases: A Case Study in using Evo and Kanban (2004...
From Waterfall to Weekly Releases: A Case Study in using Evo and Kanban (2004...From Waterfall to Weekly Releases: A Case Study in using Evo and Kanban (2004...
From Waterfall to Weekly Releases: A Case Study in using Evo and Kanban (2004...
 
Stop the line & Stop Feature Development practices
Stop the line & Stop Feature Development practicesStop the line & Stop Feature Development practices
Stop the line & Stop Feature Development practices
 
TuleapCon 2017-STMicroelectronics-Case-Study
TuleapCon 2017-STMicroelectronics-Case-StudyTuleapCon 2017-STMicroelectronics-Case-Study
TuleapCon 2017-STMicroelectronics-Case-Study
 
Moving towards a more efficient and flexible delivery model in automotive env...
Moving towards a more efficient and flexible delivery model in automotive env...Moving towards a more efficient and flexible delivery model in automotive env...
Moving towards a more efficient and flexible delivery model in automotive env...
 
Why Test SAP PI/PO after any upgrade
Why Test SAP PI/PO after any upgradeWhy Test SAP PI/PO after any upgrade
Why Test SAP PI/PO after any upgrade
 
Tackling Terraform at Ticketmaster
Tackling Terraform at TicketmasterTackling Terraform at Ticketmaster
Tackling Terraform at Ticketmaster
 
FAPI / Open Banking Conformance #fapisum - Japan/UK Open Banking and APIs Sum...
FAPI / Open Banking Conformance #fapisum - Japan/UK Open Banking and APIs Sum...FAPI / Open Banking Conformance #fapisum - Japan/UK Open Banking and APIs Sum...
FAPI / Open Banking Conformance #fapisum - Japan/UK Open Banking and APIs Sum...
 
A brief history of automation in Software Engineering
A brief history of automation in Software EngineeringA brief history of automation in Software Engineering
A brief history of automation in Software Engineering
 
The Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security TestingThe Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security Testing
 
meetup version of Paving the road to production
  meetup version of Paving the road to production    meetup version of Paving the road to production
meetup version of Paving the road to production
 
TuleapCon 2017-STMicroelectronics-Imaging-Division-Case-Study
TuleapCon 2017-STMicroelectronics-Imaging-Division-Case-StudyTuleapCon 2017-STMicroelectronics-Imaging-Division-Case-Study
TuleapCon 2017-STMicroelectronics-Imaging-Division-Case-Study
 

Recently uploaded

BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
AG2 Design
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Landownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptxLandownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptx
JezreelCabil2
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Landownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptxLandownership in the Philippines under the Americans-2-pptx.pptx
Landownership in the Philippines under the Americans-2-pptx.pptx
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 

Process synchronization in operating system

  • 1. Process Synchronization Presented by Dani Mfungo HD/UDOM/408/T.2015 CS603:computer system programming
  • 2. Objective and Outcomes • What happened when Concurrent process shared data • How to handle data inconsistency • Investigate a critical section (CS) as a protocol for synchronization • Algorithmic approach to CS implementation • Investigate classical process-synchronization problems • Producer – consumer problem • Dining –philosopher problems • Sleeping barber problems • Cigarette smokers’ problem • Investigation of tools used to solve process synchronization problems Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 3. Lets consider to approach on handling concurrent problem • LANGUAGE STRUCTURE FOR CONCURENCY PROCESS • Fork – Join • Cobegin - Coend • How do they help on construct concurrency program?? Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 4. TRANSLATE THE PRECENDENCE GRAPH TO Cobegin –Coend structure 1. Begin 2. S1; 3. Cobegin 4. S3; 5. begin 6. S2; 7. Cobegin 8. S4; 9. S5; 10. Coend 11. S6; 12. End 13. Coend 14. S7; 15. End Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 5. TRANSLATE THE PRECENDENCE GRAPH TO fork –join structure 1. Begin L1:S3 L2:S6 2. count = 3; goto L3 goto L3 3. S1; 4. fork L1 5. S2; 6. S4; 7. fork L2 8. S5; 9. L3: join count; 10. S7; 11. End Task of Join Count statement Count = count -1 If count ≠ 0 𝑡ℎ𝑒𝑛 𝑄𝑢𝑖𝑡 Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 6. Which structure is better than Other? What is solution for a system which implement Cobegin – Coend structure ??? • It is impossible to write Cobegin – Coend Here • Fork –join is the best solution ? Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 7. PRODUCER / CONSUMER PROBLEM What will happen if • the rate to producer is greater than the rate to consume? • Rate to producer < rate to consume? • Rate to produce == to Rate to consume? • Producer generate Items • Consumer consume item Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 8. PRODUCER – CONSUMER PROBLEM-> SOLUTION Two Situation 1. Unbounded Buffer 2. Bounded buffer – limited size When buffer is buffer is full, • producer wait until items are consumed • Rate of consumption > rate of production, result to empty buffer Producer Consumer problems also known as Bounded Buffer Problem Buffer (n) P c Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 9. bounded buffer problem • Solution to this must satisfy the following condition 1. A producer must not overwrite a full buffer 2. Consumer must not consume an empty buffer 3. Consumer and buffer must access buffer in a mutually exclusive manner • Variable count keep track number of item (N) in buffer • For Producer • If count = n -> buffer is full then producer go to sleep • If count ≠ 𝑛 producer add item and increment count • For Consumer • If count = 0 - > buffer empty, consumer go to sleep • If count ≠ 0 consumer remove an item and decrement counter Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 10. bounded buffer problem Is this simple algorithm free of problems?? Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 11. Producer Process count + 1 A: R1 = count B: R1 = R1+ 1 C: count = R1 Consumer Process count -1 D: R2 = count E: R2 = R2-1 F: count = R2 Bounded buffer weakness & race condition Execution sequence A R1 =7 B R1=8 D R2=7 E R2=6 C count=8 F count=6  Also consider Transaction process  Race condition result a critical section problems Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 12. CRITICAL SECTION • A critical section of a data item d is a section of code which cannot be executed concurrently with it self or with other critical section(s) for d. • PROPERTIES OF CS IMPLEMENTATION • CORRECTENESS (Mutual execution): at most one process may execute a CS at a given moment • PROGRESS: A process will take a finite time interval to execute its critical section • BOUNDED WAIT: Processes wait a finite time interval to enter their critical sections. • Absence of deadlock: Processes should not block each other indefinitely Sunday, July 10, 2016DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 13. Approaches for Implementing Synchronization • 3 Categories 1. Busy waiting 2. Hardware support 3. Operating System support 1. Dekker’s algorithm and Peterson’s algorithm are used for Busy waiting 2. Disable interrupt for accessing hardware facilities 3. Mechanism and tools such as semaphores and monitors are used by OS Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 14. CRITICAL SECTION • Entry section make decision if process should enter CS or not • Shared Lock mechanism is used for CS • Process enter a exit section after CS Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015 ENTRY SECTION { } EXIT SECTION { CRITICAL SECTION REMINDER SECTION } Decision made, locking mechanism Decision made, locking mechanism (unlock process) Reminder section (other part of the code)
  • 15. Simple natural solution • Synchronization between two process P1 and P2 • Each process wait for the other to leave CS • Implement shared variable process_turn • While loop act as entry section and if variable = 1, P1 enter CS otherwise if 2, P2 enter CS • P1 finish execution, initialize process_turn to 2, P2 execute also. • What if P2 still in non critical section and don’t want to execute? • This approach / protocol will satisfy ME but not Progress Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 16. • Only Mutual execution are granted • Progress is not work in this situation Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 17. Another Solution • The algorithm is that it does not save the state of the executing process • To store the state of the process, two more variables, namely, state_flag_P1 and state_flag_P2 • If a process enters its critical section, it first sets this state flag to zero, and after exiting, it sets it to one • It indicates that if a process is using its CS, then the other process must wait until the state flag becomes one, • state flag variables eliminate the problem of progress • Also this solution suffer from other problem as well – don’t guarantee Mutual execution since • In the beginning, when no process is executing, both P1 and P2 will try to enter the critical section consider diagram Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 18. Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 19. 3rd Solution • Setting state_flag_P1 and state_flag_P2 to 0 before the while loop • This will solve the problem of mutual exclusion, but there still is one problem • Suppose, at the moment P1 starts and executes its first statement as state_ flag_P1 = 0, P2 interrupts and gets the execution and executes its first statement, state_ flag_P2 = 0. • In this situation, if P2 continues and executes its while loop, then it will not be able to proceed as it is waiting for P1 to set state_ flag_P1 to 1. • Both the processes are waiting for each other, thereby causing deadlock in the system. Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 20. • Two result • Dead lock and livelock Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 21. Dekker’s Solution • This algorithm satisfies all the rules of the designed protocol. • Both the processes will not try to enter simultaneously due to the variable, process_turn and will satisfy the mutual exclusion property. • If P1 starts first and finds that state_ flag_P2 = 0, that is, P2 wants to enter the CS, it will allow P2, only when process_turn = 2. • Otherwise, it will wait for state_ flag_P2 to be 1 so that P1 can enter its CS. If state_ flag_P2 = 1 initially, then P1 will skip the while loop and straightway enter the CS. • In this way, there will not be any deadlock or livelock. • Moreover, the chance is given to only those processes that are waiting in the queue to enter the CS. Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 22. Dekker’s Solution Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 23. Peterson’s Solution • easier method compared to Dekker’s solution var flag: array [0..1] of Boolean; Turn : 0..1; Pi Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015 Flag [i] =true; Turn =j; While(flag[i] and turn=j) do skip; CS Flag [i] = false;
  • 24. • process_turn takes the value zero for Process P1 and one for Process P2 • For the process flag, a Boolean array process_ flag[] is taken that consists of two values, 0 for P1 and 1 for P2 • The variable process_turn maintains the mutual exclusion and process_ flag[] maintains the state of the process. • Initially, both the processes make their flags true but to maintain the mutual exclusion, the processes before entering their critical sections allow other processes to run • After exiting the critical section, the process makes its flag false so that the other process can start if it wants. Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 25. Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015 Peterson’s Solution
  • 26. SEMAPHORE • The semaphore is used to protect any resource such as global shared memory that needs to be accessed and updated by many processes simultaneously • Semaphore acts as a guard or lock on the resource • Whenever a process needs to access the resource, it first needs to take permission from the semaphore • The semaphore is implemented as an integer variable, say as S, and can be initialized with any positive integer values. • The semaphore is accessed by only two indivisible operations known as wait and signal operations, denoted by P and V, respectively • Whenever a process tries to enter the critical section, it needs to perform wait operation Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 27. SEMAPHORE cont… • Initially, the count of semaphore is 1 • It decrement to zero when process accesses the available critical area • When a process exits the critical section, it performs the signal operation • The semaphore whose value is either zero or one is known as binary semaphore • semaphore that takes a value greater than one is known as counting semaphore. • In binary semaphore,the CS locked by a process may be unlocked by any other process. • However, in mutex, only the process that locks the CS can unlock it. Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 28. Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015 one problem in the implementation of such a semaphore • When a process does not get access to the critical section, it loops continually waiting for it. • This does not produce any result but consumes CPU cycles, thereby wasting the processor time Mutex: semaphore mutex=1 Pi: P(mutex) CS V(mutex) RS
  • 29. SOLUTION OF CLASSIC SYNCHRONIZATION PROBLEMS USING SEMAPHORES • PROCESS SYNCHRONIZATION Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015 P(sync) Sj Si V(sync) Si Sj Sync:semaphore Sync = 0; S1 S2 . . . Si Si+1 Si+2 . . U1 U2 . . . Uj Uj+1 Uj+2 . . V(s) P(s) Wait for Ui to finish Sequence: J1 J2 Run concurrently
  • 30. SOLUTION OF CLASSIC SYNCHRONIZATION PROBLEMS USING SEMAPHORES • SOLUTION OF Cobegin – coend synchronization process Variable a,b,c,d,e,g: semaphore 1. Begin 2. Cobegin 3. S1; V(a);V(b); end 4. P(a); S2;S4;V(c);V(d); 5. P(b); S3; V(e); 6. P(c);S5;V(f); 7. P(d);P(e);S6;V(g); 8. P(f);P(g);S7; 9. coend 10. End Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015
  • 31. Type semaphore = record value= integer; L: list of processes; end; Var S:semaphore; Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015 TO OVERCOME A BUSY WAIT PROBLEM Define a semaphore AS structure or records and not integer V(S): S.Value=S.Value+1 If S.value ≤ 0 then Begin Remove process P from S.L //put P into ready queue Wakeup(P); End; P(S): S.Value=S.Value-1 If S.value<0 then Begin Add this process to S.L // into wait state Block; End;
  • 32. SOLUTION OF CLASSIC SYNCHRONIZATION PROBLEMS USING SEMAPHORES • PRODUCER/ CONSUMER PROBLEM full,empty,mutex:semaphore nextp, nextc:item full =0; empty=n; mutex=1; Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015 Consumer: repeat P(full) P(mutex) …… Remove an item from buffer to nextc …… V(mutex) V(empty) Until false; Producer: repeat production on item in nextp; ….. P(empty) P(mutex) …… Add nextp to buffer …… V(mutex) V(full) Until false; CONSUMERPRODUCER
  • 33. Demostration Simulation about Process synchronization Sunday, July 10, 2016 DANI ELIAS MFUNGO HD/UDOM/408/T.2015