Lecture 2 Concurrency
Lecture 2 Concurrency
Mark Stanovich
Operating Systems
COP 4610
Why Concurrency?
Allows multiple applications to run at
the same time
Analogy: juggling
Benefits of Concurrency
Benefits of Concurrency
Ability to run multiple applications at
the same time
Better resource utilization
Resources unused by one application
can be used by the others
Better average response time
No need to wait for other applications to
complete
Benefits of Concurrency
Better performance
One application uses only the processor
One application uses only the disk drive
Completion time is shorter when running
both concurrently than consecutively
Drawbacks of Concurrency
Drawbacks of Concurrency
Applications need to be protected from
one another
Additional coordination mechanisms
among applications
Overhead to switch among
applications
Potential performance degradation
when running too many applications
Thread
A sequential execution stream
The smallest CPU scheduling unit
Can be programmed as if it owns the
entire CPU
Implication: an infinite loop within a thread
won’t halt the system
Illusion of multiple CPUs on a single
machine
Thread States
Program counter
Register values
Execution stacks
Thread Benefits
Simplified programming model per
thread
Example: Microsoft Word
One thread for grammar check; one
thread for spelling check; one thread for
formatting; and so on…
Can be programmed independently
Simplifies the development of large
applications
Address Space
Contains all states necessary to run a
program
Code, data, stack(s)
Program counter(s)
Register values
Resources required by the program
Status of the running program
Process
An address space + at least one
thread of execution
Address space offers protection among
processes
Threads offer concurrency
A fundamental unit of computation
Process =? Program
Program: a collection of statements in
C or any programming languages
Process: a running instance of the
program, with additional states and
system resources
Process >? Program
Two processes can run the same
program
The code segment of two processes are
the same program
Program >? Process
A program can create multiple
processes
Example: gcc, netscape
Analogy
Program: a recipe
Process: everything needed to cook
e.g., kitchen
Two chefs can cook the same recipe in
different kitchens
One complex recipe can involve
several chefs
Some Definitions
Uniprogramming: running one
process at a time
Running
Ready Blocked
I/O complete
Program and Process
text
data
Source Code
int main()
heap
{
…
}
free space
stack