9. Intro to Scheduling Flashcards
What are the three states of a thread?
Running (executing instructions on a CPU), ready (not executing, but capable), and waiting/blocking/sleeping (not executing, not able to start yet)
Why does a thread transition from running to ready?
it was descheduled
Why does a thread transition from running to waiting?
it performed a blocking system call
Why does a thread transition from waiting to ready?
the event the thread was waiting for happened
Why does a thread transition from ready to running?
it was scheduled
Why does a thread transition from running to terminated?
it exited or hit a fatal exception
What is scheduling?
The process of choosing the next thread (or threads) to run on the CPU(s)
Why do we schedule threads?
We generally have more threads than cores to run them on, so we need to multiplex the CPU.
We (with the kernel) are also in charge of allocating the CPU and must try to make good decisions so applications can run properly
When are the 4 times that scheduling happens?
- When a thread voluntarily gives up the CPU by calling yield().
- When a thread makes a blocking system call and must sleep until the call completes
- When a thread exits.
- When the kernel decides that a thread has run for long enough (preemptive policy, not cooperative)
What makes a scheduling policy preemptive as opposed to cooperative?
The kernel preempts (or stops) a thread that has not requested to be stopped
What is the rationale behind having a way for threads to voluntarily give up the CPU?
yield() can be a useful way of allowing a well-behaved thread to tell the CPU that it has no more useful work to do (which is inherently cooperative)
What is the mechanism component of scheduling?
How we switch between threads
What is the policy component of scheduling?
How we choose the next thread to run
How do we switch between threads?
Perform a context switch and move threads between the ready, running, and waiting queues
Is this an example of scheduling policy or mechanism:
Deciding what thread to run
Policy
Is this an example of scheduling policy or mechanism:
Context switch
Mechanism
Is this an example of scheduling policy or mechanism:
Maintaining the running, ready, and waiting queues
Mechanism
Is this an example of scheduling policy or mechanism:
Giving preference to interactive tasks
Policy
Is this an example of scheduling policy or mechanism:
Using timer interrupts to stop running threads
Mechanism
Is this an example of scheduling policy or mechanism:
Choosing a thread to run at random
Policy
Why (and in what ways) does the scheduling implementation impact other parts of the system?
Using other system resources requires the CPU.
Intelligent scheduling makes a modestly-powered system seem fast and responsive.
Stupid scheduling makes a powerful system seem sluggish and laggy.
What is system “responsiveness”?
When you give the computer an instruction or input, it responds in a timely manner (it doesn’t have to finish, just show you that it’s started)
What are some examples of responsive tasks we use computers for?
Web browsing (clicking a link retrieves a webpage), editing (typing a key, it’s rendered on screen), chatting (hit send, text transmits to target)
What is system “continuity”?
When you ask the computer to perform a continuous task, it does so smoothly