Download Thread Scheduling

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CHAPTER 6 – 10/12/00 ==> 3/19/03
Threads Scheduling
CS 350 – Fall 2000/Spring 2003

Thread scheduling
-
User level threads managed by the Thread library and kernel unaware of
them.
-
To get to the CPU, user level threads ultimately are mapped to kernel
threads. May be indirect, ex: LWP’s

Thread library schedules user threads to an LWP (multiplexing)

Local scheduling on an application basis
But: kernel threads schedules on global basis
 this is the basis of the text discussion.

Solaris Scheduling (sect 6.7.1)
-
priority based ==> 4 priority classed:
=>
=>
=>
=>
Real time
System
Time sharing
Interactive
The last two are generally combined into a single priority.
-
A process starts with one LWP and is able to create new LWP’s as
needed
-
LWP’s inherit scheduling class and priorities of parent processes
-
Default priority class is the time sharing class
-
Inverse relationship between priority and time slice
Chapter 6 Threads Scheduling
10/24/00, 3/19/03
page 1
-
Interactive same as TS, but windowing gets higher priority
-
System class runs kernel process threads


unchanged once established
reserved for system use – NOT “kernel mode” user processes.
-
Real time given highest priority
-
There exists a set of priorities within each scheduling class … these are
ultimately mapped or converted to global priorities by scheduler –
highest global priority runs first.
-
Thread runs until:
Blocks
Time slice tuns out
Pre-empted by higher priority … round robin used a tiebreaker.
-
See Fig. 6.10 (included in slides).
Chapter 6 Threads Scheduling
10/24/00, 3/19/03
page 2
Java Thread Scheduling
Not used for Spring 2003
 Java Thread Scheduling
- Pre-emptive , priority based
- Schedules the “runnable” threads with highest priority … see fig 5.10, p. 128
Tie breaker is FIFO
- Scheduling driven by:
1. Currently running thread exits the Runnable state. A thread may leave the
runnable state by: blocking for I/O, exiting the run() method, or having
suspend() or stop() called.
2. pre-emption of current thread by higher priority thread
 Time Slicing
- An implementation decision – not part of JVM Spec.
- Runnable thread executed
For: time quantum (if time sliced)
Or
Until it exits or is preempted.
- Cooperative multi-tasking possible:
Thread can call “Thread.Yield()”
Chapter 6 Threads Scheduling
10/24/00, 3/19/03
page 3
 Java Thread Priorities
- Priorities are positive integers
- Given default priority on creation
- The program itself can change its priority (!)
- JVM does not change priorities dynamically
- Thread class uses:
Thread.MIN_PRIORITY ==> min priority = 1
Thread.MAX_PRIORITY ==> max priority = 10
Thread.NORM_PRIORITY ==> default priority = 5
- Thread inherits priority of creating thread.
- Thread can change its priority by calling the method:
SetPriority(x) , where x is the priority
See fig. 6.10 p. 159 (Silber – “Java Book”)
Chapter 6 Threads Scheduling
10/24/00, 3/19/03
page 4
 Java based round robin scheduling – an implementation (sect 6.73, page 159)
(optional)
- This implementation is illustrated by java code in fig. 6.11 and 6.12
Download the completed runnable code from the author’s web site.
- Scheduler contains a single queue of threads to select from.
- Scheduler itself runs as a separate thread of priority 6.
- Scheduled threads are priority 2 (waiting to run) or 4 (running/scheduled to
run) - Both priorities are in the “runnable” state.
- Operation: see fig 6.11, 612 or downloaded code (note the code shown in the
book does not include the queue class.
- After scheduling a thread to run, the scheduler sleeps for a quantum.
On awakening it pre-empts currently running thread which in turn goes to
sleep, and now a new thread is scheduled.
- If there are no threads in the queue, the scheduler polls in a spin loop ==> it
now has CPU time “to burn” (nothing else to run). When a new thread
arrives in the queue, it gets scheduled and the scheduler now sleeps.
- The queue is a circular list
- Can eliminate the spin loop for empty queue in the scheduler by having the
method isEmpty() to tell the scheduler that the queue is empty – scheduler can
sleep during the poll
Chapter 6 Threads Scheduling
10/24/00, 3/19/03
page 5