Semaphores Classical OS Problems - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Semaphores Classical OS Problems

Description:

Sec 2.3 Methods to Protect Critical Regions. Ch 2.4 Design ... Random Sleeper for this Wakeup is Triggered. Binary Semaphores. Mutex. Like a Standard Lock ... – PowerPoint PPT presentation

Number of Views:83
Avg rating:3.0/5.0
Slides: 19
Provided by: kna4
Category:

less

Transcript and Presenter's Notes

Title: Semaphores Classical OS Problems


1
SemaphoresClassical O/S Problems
  • Ch 2.3 and 2.4
  • Thursday, February 1, 2007

2
Todays Schedule
  • Sec 2.3 Methods to Protect Critical Regions
  • Ch 2.4 Design Issues for O/S
  • Mutual exclusion
  • Dining Philosophers Problem
  • Tuesday, February 6 - Test 1
  • Ch 1
  • Ch 2 (2.1 2.4)

3
Objectives
  • Recognize need for Mutual Exclusion in the design
    of operating systems
  • Identify software and hardware techniques for
    protecting critical regions, and compare between
    the methods
  • Experience the complexity in guaranteeing mutual
    exclusion among processes competing for the same
    resources

4
Review Critical Regions
  • Four conditions to provide mutual exclusion
  • No two processes simultaneously in critical
    region
  • No assumptions made about speeds or numbers of
    CPUs
  • No process running outside its critical region
    may block another process
  • No process must wait forever to enter its
    critical region

5
Basic Mutual Exclusion
  • Disable Interrupts (BAD!)
  • Only works for one Processor
  • User must remember to re-enable interrupts
  • Lock Variable (GETTING CLOSER)
  • How do you lock the lock?
  • Lockstep Alternation (ALMOST)
  • Violates 3rd rule of Critical Regions

6
Mutual Exclusion with Busy Waiting
  • Proposed solution with spin lock and Strict
    alternation
  • (a) Process 0. (b) Process 1.

7
Mutual Exclusion with Interested Flags Busy
Waiting
  • Peterson's solution for achieving mutual exclusion

8
Basic Mutual Exclusion (cont.)
  • Interested Flags (Petersons Solution)
  • Test Set uses hardware
  • Atomic Action
  • Read Value to see locked
  • Automatically set to locked, just in case
  • Sleep Wakeup
  • System calls
  • Block instead of busy waiting

9
Semaphores
  • Tracks number of Sleeps Wakeups
  • Down (decrements) Up (increments)
  • Historically P V Dutch (Thanks, Dijkstra!)
  • 0 no wakeups saved, 2 2 wakeups pending
  • Special Cases
  • Down (sleep) from a 0
  • Process or Thread Sleeps until a new Wakeup
  • Up (wakeup) from 0
  • Random Sleeper for this Wakeup is Triggered

10
Binary Semaphores
  • Mutex
  • Like a Standard Lock
  • Atomicity Provides Self-Locking
  • Idle Wait
  • If Locked, Thread Yields
  • Simpler Semaphores
  • Fundamental Mutual Exclusion Tool

11
Monitors Barriers
  • Monitors Higher level
  • Compiler Based Mutual Exclusion
  • Condition Variables (full)and operations on them
  • Wait
  • Signal
  • Barriers
  • Forced Resynchronization of Groups of Processes
  • Ex. By phases

12
Barriers
13
IPC (Dining Philosophers)
  • Multiple processes attempting to obtain multiple
    resources
  • Not enough resources to satisfy all requests at
    all times (Wait necessary)
  • Starvation
  • Deadlock
  • Fair allocation

14
Philosopher Resolution?
  • Patterned locking?
  • Take left, then take right?
  • Locking the entire find fork area?
  • Steal your forks while no one else can
  • State Array?
  • Track who has forks, who is waiting

15
Readers Writers (Models Database)
  • Multiple readers can co-exist
  • Two people can read the same page
  • Multiple writers cannot
  • Two people cannot write the same page, they will
    forever be getting in the way
  • Writers and readers cannot co-exist
  • Cannot read what is not written

16
Readers Writers (cont)
  • Reader on Reader
  • Allow it in
  • Reader on Writer
  • Writer on Writer
  • Must wait for Writer to finish
  • Writer on Reader
  • Must wait for Reader to finish

17
Tuesday, February 6
  • Test 1 on Tuesday, Feb 6
  • Chapter 1 and Chapter 2 (2.1 2.4)
  • Practice/review on website

18
Summary
  • Processes Threads allow for pseudo-simultaneous
    execution of tasks
  • Coordination between processes how?
  • Locking Sleeping
  • TSL Command
  • Counting Wakeups
  • Monitors
Write a Comment
User Comments (0)
About PowerShow.com