Threads, race conditions, deadlock, mutexes, semaphores, the actor model, async I/O, memory models and amdahl's law.
39 cards · basic cards · AI-written, checked twice. Edit anything.
- What is a thread?
Show answer
The smallest unit of execution within a process, capable of running concurrently with other threads in the same process.
- Define concurrency.
Show answer
The ability of a program to deal with multiple tasks being interleaved in execution, not necessarily executing at the same instant.
- Define parallelism.
Show answer
Multiple tasks executing truly simultaneously on different physical processors or cores.
- What is context switching?
Show answer
The process of storing and restoring the state of a thread so the CPU can switch between executing different threads.
- What is a critical section?
Show answer
A code segment where a thread accesses shared resources and must not be interrupted by other threads.
- What is a race condition?
Show answer
A bug where the outcome of a program depends on the unpredictable order in which multiple threads execute.
- What is mutual exclusion?
Show answer
The guarantee that only one thread can execute a critical section at any given time.
- What is deadlock?
Show answer
A situation where two or more threads are blocked forever, each waiting for the other to release a resource.
- List the four Coffman conditions for deadlock.
Show answer
Mutual exclusion, hold and wait, no preemption, and circular wait.
- How can you prevent deadlock?
Show answer
Break at least one Coffman condition, such as using timeouts, resource ordering, lock-free algorithms, or allowing preemption.
- What is a mutex?
Show answer
A synchronization primitive that acts as a mutual exclusion lock, allowing only one thread to hold it at a time.
- How does a mutex work?
Show answer
A thread acquires the mutex before entering a critical section and releases it upon exit, blocking other threads that try to acquire it.
- What is lock contention?
Show answer
The situation where many threads compete to acquire the same lock, causing performance degradation and increased waiting times.
- What is a semaphore?
Show answer
A synchronization primitive that maintains a counter, allowing threads to increment or decrement it and block if the counter would go negative.
- What is a binary semaphore?
Show answer
A semaphore with a counter that can only be 0 or 1, functionally equivalent to a mutex.