29-JAN-2004

Lecture Outline

Note: Only topics are listed here, make sure you see class notes for details
- Anoop Gupta

Synchronization & Semaphores


  1. Final Critical Section Solution for Two processes
    -- Class Activity: Write-up submission analysing final critical section solution for two processes --
  2. Bakery Algorithm
  3. Semaphores
    Motivation for using Semaphores - Problems/Limitations of using locks
    - Implemented as sequence of assembly instructions
    - Requirement to place ordering on scheduling of processes
  4. Definition of Semaphores
  5. Methods for P() and S()
  6. Mutual Exclusion with Semaphores


Discussion Details

Java Threads

There are two ways:
  1. extend Thread class
  2. implement Runnable interface
Prefer 2nd method. One reason for this is that you can extend only one class at a time. Like, if your class extends JFrame and you also need threads then you will have to use:
class TestClass extends JFrame implements Runnable {
    ...
}

Java Thread APIs (Ref: Silberschatz)
- suspend()
- sleep()
- wakeup()
- stop()

Java Thread States (Ref: Silberschatz)
- New: when you do new Thread()
- Runnable: when you do thread.start()
- Blocked: if you do thread.suspend() or if the thread is waiting for an I/O
- Dead: when thread exits after execution or when you do thread.stop()

A blocked thread can be brought back to Runnable state by using thread.wakeup()

Note: The waiting and running states of processes is  seen as one runnable state in Java threads.  The Java Virtual Machine (JVM) internally handles the operation performed by schedular/dispatcher to switch among threads in the runnable state.


CS 537 - Introduction to Operating Systems (Spring 2004)                                                                                Anoop Gupta