3 Concurrency Vs Parallelism
3 Concurrency Vs Parallelism
3 Concurrency Vs Parallelism
This lesson clari es the common misunderstandings and confusions around concurrency and parallelism.
Introduction
Serial Execution
When programs are serially executed, they are scheduled one at a time on
the CPU. Once a task gets completed, the next one gets a chance to run.
Each task is run from the beginning to the end without interruption. The
analogy for serial execution is a circus juggler who can only juggle one
ball at a time. Definitely not very entertaining!
Concurrency
A concurrent system can have two programs in progress at the same time
where progress doesn't imply execution. One program can be suspended
while the other executes. Both programs are able to make progress as
their execution is interleaved. In concurrent systems, the goal is to
maximize throughput and minimize latency. For example, a browser
running on a single core machine has to be responsive to user clicks but
also be able to render HTML on screen as quickly as possible. Concurrent
systems achieve lower latency and higher throughput when programs
running on the system require frequent network or disk I/O.
Going back to our circus analogy, a concurrent juggler is one who can
juggle several balls at the same time. However, at any one point in time,
he can only have a single ball in his hand while the rest are in flight. Each
ball gets a time slice during which it lands in the juggler's hand and then
is thrown back up. A concurrent system is in a similar sense juggling
several processes at the same time.
Parallelism
Revisiting our juggler analogy, a parallel system would map to at least two
or more jugglers juggling one or more balls. In the case of an operating
system, if it runs on a machine with say four CPUs then the operating
system can execute four tasks at the same time, making execution
parallel. Either a single (large) problem can be executed in parallel or
distinct programs can be executed in parallel on a system supporting
parallel execution.
Concurrency vs Parallelism