Concurrency (L21) Flashcards
Concurrency refers to the concept of separate threads of control/execution within a program.
True.
Parallelism is a synonym for concurrency.
False.
What are parallel programs?
Programs that support simultaneous execution of distinct instruction streams.
By definition, concurrent programs are run on multiple CPUs or cores.
False - parallel programs are.
What are parallel programs typically used for?
Increasing the performance
of a specific algorithm.
What is concurrency typically used for?
For dividing the logic of a complex programs into distinct units.
All concurrent programs provide parallelism, but parallel programs are not necessarily concurrent.
False, all parallel programs provide
concurrency, but concurrent programs are not necessarily parallel.
Controlling access to shared data is necessarily the primary issue when writing concurrent programs.
False - sharing write-able data is a problem, but sharing read-only data is fine.
What is a critical region?
A block of code in which an update to shared data is made.
What is the traditional approach to only allowing one thread to enter/exit the critical region at a time.
Locks, which are locked (1) at the start of the critical region and closed (0) at its end.
Threads that encounter a lock perform another task and circle back later.
False - such threads wait/block until the data is unlocked.
It is not possible for multiple threads to think they have the lock for some data, as setting a lock variable is done in a single line of code.
False - this single high level language instruction is compiled into multiple
machine level instructions.
What is a “test and swap” instruction provided by modern CPUs?
An atomic assignment instruction that
always completes - allows languages to close locks “in a single instruction”.
What C library allows concurrency that follows the lock model?
pthreads
What does Java’s synchronized keyword do?
A synchronized method is tested such that this method can only be used by one thread at a time.