Concurrency Flashcards
(22 cards)
What’s the main difference between threads and processes?
Threads of the same process share the same address space
Allowing multiple threads within the same process to share the same address space allows the threads to be…
independent of each other
What do the threads within a process share?
Process ID
Address space
Open files
Other resources
What does each thread within a process have, that it doesn’t share?
Thread ID
Set of registers - including PC
Stack
Give the definition:
A thread based on the POSIX library where an API specifies the behaviour of its library
POSIX thread - Pthread
What sort of results can concurrency lead to?
Non-deterministic results - different results despite the same input
⭐️ Give the definition:
When multiple threads of execution update the shared data structure, and the final result depends on the execution order
Race condition
⭐️ Give the definition:
An operation that completes in its entirety without worrying about interruption by any other potentially conflict-causing threads
Atomic operation
⭐️ What do we call the problem that is to ensure that when one thread is executing in its critical section, no other thread is allowed to execute in that critical section?
The critical section problem
⭐️ Give the definition:
A piece of code that accesses a shared resource, usually a variable or data structure
Critical section
⭐️ What are the three parts of the solution to the critical section problem?
- Mutual exclusion
- Progress
- Bounded
⭐️ Give the definition:
A part of the solution to the critical section problem where only one thread is allowed in the critical section at a time
Mutual exclusion
⭐️ Give the definition:
The part of the solution to the critical section problem that ensures that no deadlock occurs; where if there are several simultaneous requests from threads, one must be allowed to proceed
Progress
⭐️ Give the definition:
The part of the solution to the critical section problem that ensures that no starvation happens; where one must eventually allow each waiting thread to enter
Bounded
⭐️ What are the 3 concurrency problems?
- Race conditions
- Critical section problem
- Deadlocks
⭐️ Give the definition:
Threads waiting forever for each other to release resources
Deadlock
⭐️ What 3 techniques can be used to solve the concurrency problems?
- Locks (mutexes)
- Condition variables
- Atomic operations
⭐️ Give the definition:
Mutual exclusion primitives to protect critical sections. Only one thread can hold them at once.
Lock
⭐️ Give the definition: allow threads to wait for certain conditions to be true
Condition variables
⭐️ A critical section is a piece of code in a process / thread that accesses shared data (T/F)
True
⭐️ What is a race condition?
1. A mechanism to ensure mutual exclusion in critical sections.
2. A type of deadlock where threads are waiting indefinitely
3. A synchronisation primitive used to lock resources
4. Two or more threads accessing shared data, lading to unpredictable results
4
⭐️ What are the 3 requirements for a solution to the critical-section problem?
Mutual Exclusion, Progress, Bounded Waiting