20 cards · Public · Shuffle

Concurrency & Parallelism - Threads, Locks & Race Conditions

Master the fundamentals of multi-threaded programming, synchronization primitives, and common concurrency pitfalls. Learn how to design robust, thread-safe software systems.

Cards in this deck

(20 cards)

Preview terms and definitions before starting your study session.

#1
Term
Concurrency vs. Parallelism
Definition
• Concurrency: Managing multiple tasks at once by interleaving execution on a single core or across multiple cores (about structure).
• Parallelism: Executing multiple tasks simultaneously on physically separate processor cores or hardware (about execution).
#2
Term
Process vs. Thread
Definition
• Process: An isolated execution environment with its own private virtual memory space (heap, stack, code).
• Thread: A lightweight unit of execution within a process that shares memory (heap, code, global data) with sibling threads, keeping only its own stack and instruction pointer.
#3
Term
Critical Section
Definition
A segment of code that accesses shared resources (such as memory, global variables, or files) that must not be concurrently accessed by more than one thread or process to prevent data corruption.
#4
Term
Race Condition
Definition
A defect occurring when the output or state of a system depends on the uncontrolled relative timing or sequence of thread execution. Occurs when two or more threads access shared state concurrently, and at least one access is a write.
#5
Term
Race Condition Code Example & Solution
Definition
A non-atomic increment counter++ involves three instructions: read, modify, write back. Interleaving causes lost updates.
Vulnerable:
python1 line
counter += 1  # Not thread-safe
Thread-Safe Fix:
python2 lines
with lock:
    counter += 1
#6
Term
Mutex (Mutual Exclusion Lock)
Definition
A synchronization primitive used to enforce single-thread access to a critical section. A mutex has an ownership concept: only the specific thread that acquired (locked) the mutex can release (unlock) it.
#7
Term
Semaphore
Definition
A signaling mechanism that maintains a non-negative integer counter controlling access to a pool of shared resources.
• acquire() / wait() / P(): Decrements the count. Blocks if count is .
• release() / signal() / V(): Increments the count, unblocking a waiting thread.
#8
Term
Binary Semaphore vs. Mutex
Definition
• Binary Semaphore: Counter restricted to values or . Lacks ownership semantics; thread can acquire it while thread releases it (useful for signaling).
• Mutex: Possesses strict ownership; only the thread that locks it can unlock it.
Showing 8 of 20 cards in this deck.
Study All Now