Operating Systems – CSCI 402
Ch 3: Basic Concepts
http://merlot.usc.edu/william/usc/
1
321 0
Copyright ý . ¡¯s Next?
So far, we have talked about abstractions
processes, files, threads
stuff at the user level
We are not ready to talk about the OS yet Next step is something in between
Abstractions (processes, files, threads)
context for execution
I/O architecture
dynamic storage allocation
linking & loading booting
User OS
321 0
Operating Systems – CSCI 402
2
Copyright ý . Systems – CSCI 402
3.1 Context Switching
Procedures
Threads & Coroutines Systems Calls Interrupts
3
321 0
Copyright ý . magic of OS
to provide the illusion that applications run concurrently and each application thinks it¡¯s the only application running on the processor
The OS switches the processor from one application to another
switching happens transparently to the applications What is the OS doing when an application is running?
Application1 Application2 Application3
Operating Systems – CSCI 402
Context Switching
4
321 0
Copyright ý . Cheng
turns out the stack is complicated
in reality, it¡¯s just the current stack frame of the current
thread
what¡¯s below the current stack frame (and the rest of the
address space) is also part of the thread¡¯s state/context
321 0
Operating Systems – CSCI 402
Context
What¡¯s the execution context of a thread?
if we are going to talk about context switching, we need to know what we are switching and how to get back
The execution context of a thread is the current state of our thread what does the execution context include?
CPU registers, including the instruction pointer, stack pointer, base/frame pointer, etc.
stack
open files
etc.
i.e., everything that may affect the execution of the thread
5
Copyright ý . Systems – CSCI 402
3.1 Context Switching
Procedures
Threads & Coroutines Systems Calls Interrupts
6
321 0
Copyright ý . Cheng
int main() {
int i;
int a;
…
i = sub(a, 1);
…
return(0);
Subroutines
int sub(int x, int y) {
// computes x^y
int i;
int result = 1;
for (i=0; i