Topic:
Semaphore
Contents
• What is Semaphore
• Types of Semaphore
• Counting Semaphore
• Binary Semaphore
• Counting Semaphore vs Binary Semaphore
• Limitations of Semaphore
2
What is Semaphore?
• Semaphores are integer variables, stores the entire wake up calls
• On which read, modify, update happens automatically in kernel mode
• Needs support from OS to be implemented
3
Continue
P(Semaphore s) { s = s - 1;
if (s <= 0) {
// add process to queue
block(); }
}
V(Semaphore s) {
s = s + 1;
if (s <= 0) {
// remove process p from queue
wakeup(p); }
}
4
Types Of Semaphore
According to the demand of the situation
• Counting Semaphore
• Binary Semaphore or Mutex
5
Counting Semaphore
• When we need to execute more than one process in critical section at the same
time.
• The value of counting semaphore at any point of time indicates that the maximum
number of processes that can enter the critical section at the same time.
6
Example:
• A counting semaphore was initialized to 12. then 10P(wait) and 4V
signal operation was computed on this semaphore.
1. S= 12 (initially)
2. 10P wait
3. SS= S-P=2
4. Then signal 4V
5. So Total SS = 4+2 = 6
7
Binary Semaphore
• Strictly provides mutual exclusion.
• Rather than having more than 1 slot, we can only have one process in the critical
section.
• Have only two value 0 and 1
• Extended version of counting semaphore.
8
Counting Semaphore vs Binary Semaphore
Counting Binary
1. No mutual exclusion. 1. Mutual exclusion
2. Any integer value 2. Value is 0 and 1
3. More than one slot 3. Only one slot
4. Provide set of Processes 4. Have mutual exclusion mechanism.
9
Limitations of Semaphore
• Priority Inversion is a big limitation of semaphores.
• Their use is not enforced, but is by convention only.
• With improper use, a process may block indefinitely. Such a situation is
called Deadlock.
10
Thank You
11

Semaphore

  • 1.
  • 2.
    Contents • What isSemaphore • Types of Semaphore • Counting Semaphore • Binary Semaphore • Counting Semaphore vs Binary Semaphore • Limitations of Semaphore 2
  • 3.
    What is Semaphore? •Semaphores are integer variables, stores the entire wake up calls • On which read, modify, update happens automatically in kernel mode • Needs support from OS to be implemented 3
  • 4.
    Continue P(Semaphore s) {s = s - 1; if (s <= 0) { // add process to queue block(); } } V(Semaphore s) { s = s + 1; if (s <= 0) { // remove process p from queue wakeup(p); } } 4
  • 5.
    Types Of Semaphore Accordingto the demand of the situation • Counting Semaphore • Binary Semaphore or Mutex 5
  • 6.
    Counting Semaphore • Whenwe need to execute more than one process in critical section at the same time. • The value of counting semaphore at any point of time indicates that the maximum number of processes that can enter the critical section at the same time. 6
  • 7.
    Example: • A countingsemaphore was initialized to 12. then 10P(wait) and 4V signal operation was computed on this semaphore. 1. S= 12 (initially) 2. 10P wait 3. SS= S-P=2 4. Then signal 4V 5. So Total SS = 4+2 = 6 7
  • 8.
    Binary Semaphore • Strictlyprovides mutual exclusion. • Rather than having more than 1 slot, we can only have one process in the critical section. • Have only two value 0 and 1 • Extended version of counting semaphore. 8
  • 9.
    Counting Semaphore vsBinary Semaphore Counting Binary 1. No mutual exclusion. 1. Mutual exclusion 2. Any integer value 2. Value is 0 and 1 3. More than one slot 3. Only one slot 4. Provide set of Processes 4. Have mutual exclusion mechanism. 9
  • 10.
    Limitations of Semaphore •Priority Inversion is a big limitation of semaphores. • Their use is not enforced, but is by convention only. • With improper use, a process may block indefinitely. Such a situation is called Deadlock. 10
  • 11.