Lecture 09
Lecture 09
1
Review of Lectures So Far
• Computer hardware (con’t)
– We need to combine the CPU with RAM and a memory bus
• The bus connects the CPU to the RAM and allows the CPU to
access address location contents
• Since we are going to load many instructions (i.e., a program)
into memory, the CPU must have a special register to keep
track of the current instruction, the program counter
– The program counter is incremented after each instruction
– Some instructions directly set the value of the program counter,
like JUMP or GOTO instruction
2
Review of Lectures So Far
• Computer hardware (con’t)
– Now we add I/O devices to the communication bus
• The CPU communicates with I/O devices via the bus
• This allows user interaction with the program (e.g., via a
terminal)
• This also allows more data and bigger programs (e.g., stored
on a disk)
3
Review of Lectures So Far
• Computer hardware (con’t)
– Since the CPU is much faster than the I/O devices it has
three options when performing I/O
• It can simply wait (not very efficient)
• It can poll the device and try to do other work at the same time
(complicated to implement and not necessarily timely)
• It can allow the I/O devices to notify it when they are done via
interrupts (still a bit complicated, but efficient and timely)
4
Review of Lectures So Far
• Providing an Operating System
– An OS must define some way to stop running the current
process and start running another, there are two options
• Implement all I/O calls to give up CPU when they might block
and provide functions to yield the CPU voluntarily; this is
cooperative multitasking
• Add a hardware timer interrupt to our CPU so that we can
automatically interrupt processes after some amount of time;
this is called preemptive multitasking
– Now that we have multiple processes running, we need some
way to protect the OS from them and them from each other
• Hardware support in the form of dual-mode CPU operation
– This means that some instructions can only be executed by the
OS and not by processes
5
Review of Lectures So Far
• Providing an Operating System (con’t)
– What does the OS do when it preempts a process?
• Saves the CPU registers for the current process since they
contain unfinished work; the CPU registers are saved in the
process descriptor in OS’s process table
– The process descriptor keeps track of all process information for
a specific process
• Saves the program counter in the process descriptor so it
knows where to resume the current process later
– What does the OS do when it gives the CPU to a process?
• Restores the process’ CPU registers from the saved values in
the process descriptor for that process
• Restores the program counter to the next instruction for the
new process
6
Review of Lectures So Far
• Providing an Operating System (con’t)
– We now have created a multitasking OS
– Is it a concurrent system? Yes, in computer science terms.
• English definition of “concurrent”
– Happening at the same time as something else
• Computer science definition of “concurrent”
– Non-sequential execution (non-deterministic)
• Definition of “parallel”
– Happening at the same time as something else
– This is the same as the English meaning of “concurrent”
• In computer science something that is parallel is also
concurrent (i.e., non-sequential), but something that is
concurrent is not necessarily parallel
7
Review of Lectures So Far
• Defining a process
– A process is a resource program counter value
container with a single execution
flow CPU register values
open files
...
call stack
8
Review of Lectures So Far
• Defining a thread
program counter value – Since multiple threads can exist in the same
process, this means that they can share lots
CPU register values of stuff, but not everything
memory (data and text) memory (data and text) program counter value
Original process
open files
...
9
Review of Lectures So Far
• Defining a lightweight process
– Sometimes the dividing line between a process and a thread
is very thin
– A lightweight process is pretty much the same as a normal
process except that it may share some resources with other
lightweight processes
• In this regard a lightweight process is very much like a thread
and can be used to implement threads
– Linux uses lightweight processes to implement threads,
which is why you can see the threads as processes when you
list process with the ps command
– Not every lightweight process is a thread
10