Week 8 Flashcards
What is concurrency?
The ability of our machine to handle and execute multiple different tasks at seemingly same time.
At the process level, programmers can manage concurrency using __________
threading
Unless explicitly synchronized, processes/threads may:
Be run in _________
Be stopped and restarted at ________
Remain stopped for _____________
any order
any time
arbitrary lengths of time
Why is the operating system one of the most difficult concurrent programs to write?
It is multiplexing access to hardware resources and therefore sharing a great deal of state between multiple processes.
It frequently uses many threads to hide hardware delays while servicing devices and application requests.
Lots of shared states plus alot of threads.
What is a race condition?
A race condition is when the output of a process is unexpectedly dependent on timing or other events.
Processes contain ________ , multiple ____ can be executing concurrently within a single process.
threads
A process thread can be thought of as …
an abstraction of the CPU state
Both processes and threads are used for concurrency. What do they do?
Processes allow for concurrency to be managed at the OS level
Threads allow for concurrency to be managed at the process level.
Why use threaeds instead of separate processes?
When the program needs cheap communication.
Lowers the cost of a context switch
Gives the programmer additional control over concurrent execution.
Communication between threads tends to use ________ objects in memory
Communication between threads tends to use shared objects in memory.
Thread stacks and local variables are intended to be _________
Thread stacks and local variables
are intended to be private
What is the difference between concurrency and atomicity?
Concurrency: the illusion that multiple things are happening at once. (requires stopping or starting any thread at any time.
Atomicity: the illusion that a set of separate actions occurred all at once.
What is a critical section?
> A critical section contains a series of instructions that only one thread should be executing at any given time.
> This series of instructions should look atomic with respect to other
threads.
What are these critical section requirements?
Mutual Exclusion
Progress/Fairness
Performance
> Mutual Exclusion: this is the most basic property. Only one thread
should be executing in the critical section at one time.
> Progress/Fairness: all threads should eventually be able to proceed through the critical section.
> Performance: we want to keep critical sections as small as
possible without sacrificing correctness.
How do we enforce critical sections?
There are 2 possible approaches.
> Don’t stop: On uniprocessors a single thread can prevent other threads from executing in a critical section by simply not being descheduled.
> Don’t enter: More generally we need a way to force other threads—potentially running on other cores—not to enter the
critical section while one thread is inside. How do we do this? Locks!