Operating System
Concepts
Instructor Name: Muhammad Asif
1
Quick Recap of Previous Lecture
• Critical Section Problem
• Condition for the Solution to the Critical Section Problem
• Race Condition
• Peterson’s Solution
2
Today’s Outlines
• Software solution to the Critical Section Problem
• Semaphore
• Wait ( )
• Signal ( )
• Types of Semaphore
• Counting semaphore
• Binary semaphore
• Advantages of semaphore
3
Semaphore
• Semaphore is an integer variables that are used to solve the
critical section problem by using two atomic operations,
• That are used for process synchronization:
• Wait()
• Signal ()
• Always initialize the variable with 1 if solving the Critical
Section Problem:
int S = 1;
4
Semaphore
do{
wait ( S ); // ftn call
// critical section // enter in its critical section
Signal ( S ); // ftn call
// termination section
• }while(true); 5
Semaphore
Where int S = 1;
do{
wait ( S ); // ftn call
// critical section // enter in its critical section
Signal ( S ); // ftn call
// termination section
}while(true); 6
Types of Semaphores
• There are two main types of semaphores i.e. counting
semaphores and binary semaphores. Details about these are
given as follows:
• Counting Semaphores
• Binary Semaphores
7
Semaphore
• Binary Semaphores
• The binary semaphores are like counting semaphores but their
value is restricted to 0 and 1.
• The wait operation only works when the semaphore is 1 and the
signal operation succeeds when semaphore is 0.
• It is sometimes easier to implement binary semaphores than
counting semaphores.
• Counting Semaphores:
• These are integer value semaphores and have an unrestricted value
domain.
• These semaphores are used to coordinate the resource access,
where the semaphore count is the number of available resources.
• If the resources are added, semaphore count automatically
incremented and if the resources are removed, the count is
decremented.
8
Advantages of Semaphores
• Semaphore is used to solve different problems like:
• Critical Section Problem
• Order of execution among the processes
• Resource Management
9
Any Questions?
10

OS Semaphore.pptx

  • 1.
  • 2.
    Quick Recap ofPrevious Lecture • Critical Section Problem • Condition for the Solution to the Critical Section Problem • Race Condition • Peterson’s Solution 2
  • 3.
    Today’s Outlines • Softwaresolution to the Critical Section Problem • Semaphore • Wait ( ) • Signal ( ) • Types of Semaphore • Counting semaphore • Binary semaphore • Advantages of semaphore 3
  • 4.
    Semaphore • Semaphore isan integer variables that are used to solve the critical section problem by using two atomic operations, • That are used for process synchronization: • Wait() • Signal () • Always initialize the variable with 1 if solving the Critical Section Problem: int S = 1; 4
  • 5.
    Semaphore do{ wait ( S); // ftn call // critical section // enter in its critical section Signal ( S ); // ftn call // termination section • }while(true); 5
  • 6.
    Semaphore Where int S= 1; do{ wait ( S ); // ftn call // critical section // enter in its critical section Signal ( S ); // ftn call // termination section }while(true); 6
  • 7.
    Types of Semaphores •There are two main types of semaphores i.e. counting semaphores and binary semaphores. Details about these are given as follows: • Counting Semaphores • Binary Semaphores 7
  • 8.
    Semaphore • Binary Semaphores •The binary semaphores are like counting semaphores but their value is restricted to 0 and 1. • The wait operation only works when the semaphore is 1 and the signal operation succeeds when semaphore is 0. • It is sometimes easier to implement binary semaphores than counting semaphores. • Counting Semaphores: • These are integer value semaphores and have an unrestricted value domain. • These semaphores are used to coordinate the resource access, where the semaphore count is the number of available resources. • If the resources are added, semaphore count automatically incremented and if the resources are removed, the count is decremented. 8
  • 9.
    Advantages of Semaphores •Semaphore is used to solve different problems like: • Critical Section Problem • Order of execution among the processes • Resource Management 9
  • 10.