29-JAN-2004
Lecture Outline
Note: Only topics are listed here, make sure you
see class notes for details
- Anoop Gupta
Synchronization & Semaphores
- Final Critical Section Solution
for Two processes
-- Class
Activity: Write-up submission analysing final critical section solution
for two processes --
- Bakery Algorithm
- Semaphores
Motivation
for using Semaphores - Problems/Limitations of using locks
- Implemented as sequence of
assembly instructions
- Requirement to place ordering on scheduling of processes
- Definition of Semaphores
- Methods for P() and S()
- Mutual Exclusion with Semaphores
Java Threads
There are two ways:
- extend Thread class
- 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