Concurrency Patterns

Design patterns for managing concurrent operations, including thread pools, futures/promises, actors, and strategies for handling shared resources and synchronization.

Category
Computer Programming
Level
advanced
Languages
en → en
Cards
49
Markdown
Concurrency Patterns (.md)

Flashcards (49)

#Front (Term / Question)Back (Definition / Answer)ExampleMultiple-Choice Options
1What is a shared resource?A shared resource is any resource that can be accessed by multiple threads or processes, requiring synchronization to prevent conflicts.
2What is optimistic concurrency control?Optimistic concurrency control is a strategy that assumes multiple transactions can complete without conflict and checks for conflicts before committing.
3What is a thread-local storage?Thread-local storage is a programming construct that allows data to be stored uniquely for each thread, preventing interference between threads.
4What is a distributed system in the context of concurrency?A distributed system is a network of independent computers that work together to achieve a common goal, often requiring coordination and synchronization among concurrent processes.
5What is a callback in asynchronous programming?A callback is a function passed as an argument to another function that is executed after a certain event or condition is met.
6What is a synchronization primitive?A synchronization primitive is a low-level construct that provides mechanisms for controlling access to shared resources in concurrent programming.
7What is a thread-safe builder pattern?A thread-safe builder pattern is a design pattern that allows the construction of complex objects in a thread-safe manner, ensuring consistent state during object creation.
8What is load balancing in concurrency?Load balancing is the distribution of workloads across multiple computing resources to optimize resource use and minimize response time.
9What is a race condition?A race condition occurs when two or more threads access shared data and try to change it at the same time, leading to unpredictable results.
10What is a critical section?A critical section is a part of the code that accesses shared resources and must not be executed by more than one thread at a time.
11What is a fork in concurrency?A fork is an operation that creates a new thread or process, allowing concurrent execution of tasks.
12What is a concurrent modification exception?A concurrent modification exception occurs when a collection is modified while it is being iterated over, leading to unpredictable behavior.
13What is the difference between a thread and a process?A thread is a lightweight process that shares the same memory space, while a process is an independent program with its own memory space.
14What is a thread-safe singleton?A thread-safe singleton is a design pattern that ensures a class has only one instance and provides a global point of access to it, safely in a concurrent environment.
15What is the actor model?The actor model is a concurrency model that treats 'actors' as the fundamental units of computation, where each actor can send and receive messages and maintain its own state.
16What is a fork-join task?A fork-join task is a task that can be split into smaller subtasks (forked) and then combined (joined) after execution, typically used in parallel processing.
17What is a thread pool executor?A thread pool executor is a component that manages a pool of threads, allowing for the execution of tasks with configurable parameters like pool size and task queue.
18What is a concurrent hashmap?A concurrent hashmap is a thread-safe implementation of a hash map that allows concurrent access and modifications by multiple threads.
19What is a condition variable?A condition variable is a synchronization primitive that allows threads to wait until a particular condition is met.
20What is a barrier in concurrency?A barrier is a synchronization point where threads must wait until all threads reach that point before any can proceed.
21What is the difference between synchronous and asynchronous programming?Synchronous programming executes tasks sequentially, while asynchronous programming allows tasks to be executed independently, often using callbacks or promises.
22What is a task in concurrent programming?A task is a unit of work that can be executed independently, often representing a single operation in a concurrent environment.
23What is a future in concurrency?A future is an object that represents the result of an asynchronous computation, allowing a program to retrieve the result once it is available.
24What is pessimistic concurrency control?Pessimistic concurrency control is a strategy that assumes conflicts will occur and locks resources to prevent concurrent access.
25What is a thread-safe cache?A thread-safe cache is a caching mechanism that allows multiple threads to read and write data concurrently without causing inconsistencies.
26What is a thread pool?A thread pool is a collection of pre-initialized threads that can be reused to execute tasks, improving performance by reducing the overhead of thread creation.
27What is a message queue?A message queue is a communication method used in concurrent programming where messages are sent between processes or threads to coordinate actions.
28What is a thread-safe collection?A thread-safe collection is a data structure designed to be safely accessed by multiple threads simultaneously.
29What is deadlock in concurrency?Deadlock is a situation where two or more threads are blocked forever, each waiting for the other to release a resource.
30What is a non-blocking queue?A non-blocking queue is a data structure that allows concurrent access without locking, enabling multiple threads to enqueue and dequeue items safely.
31What is a join in concurrency?A join is an operation that waits for a thread or process to complete before proceeding with the execution of the next task.
32What is a reactive programming model?Reactive programming is a programming paradigm focused on data streams and the propagation of change, allowing for asynchronous data handling.
33What is a non-blocking algorithm?A non-blocking algorithm allows threads to proceed without being blocked by other threads, often using atomic operations.
34What is a distributed lock?A distributed lock is a synchronization mechanism used in distributed systems to ensure that only one instance of a process can access a resource at a time.
35What is the producer-consumer problem?The producer-consumer problem is a classic synchronization problem where producers generate data and consumers process it, requiring coordination to avoid conflicts.
36What is the fork-join pattern?The fork-join pattern is a concurrency pattern where a task is split into subtasks (forked) and then combined (joined) after execution.
37What is a thread scheduler?A thread scheduler is a component of the operating system that manages the execution of threads, determining which thread runs at any given time.
38What is a task queue?A task queue is a data structure that holds tasks waiting to be executed, often used in thread pools to manage workload.
39What is a concurrent programming library?A concurrent programming library provides abstractions and tools for managing concurrency, such as thread pools, futures, and synchronization primitives.
40What is concurrency in programming?Concurrency is the ability of a program to manage multiple tasks at the same time, allowing for overlapping execution.
41What is a deadlock detection algorithm?A deadlock detection algorithm is a method used to identify deadlocks in a system, allowing for recovery or prevention strategies.
42What is a promise in concurrency?A promise is a placeholder for a value that may be available in the future, allowing for asynchronous programming by providing a way to handle eventual results.
43What is the fork-join framework?The fork-join framework is a concurrency framework that simplifies parallel programming by allowing tasks to be divided and processed in parallel and then combined.
44What is a mutex?A mutex (mutual exclusion) is a locking mechanism that ensures that only one thread can access a resource at a time.
45What is thread safety?Thread safety is a property of a program that guarantees safe execution by multiple threads without causing data corruption.
46What is a semaphore?A semaphore is a synchronization primitive that controls access to a shared resource by maintaining a count of available resources.
47What is a lock-free data structure?A lock-free data structure is designed to allow multiple threads to operate on it without the need for locks, improving performance in concurrent environments.
48What is a thread-safe iterator?A thread-safe iterator is an iterator that can be safely used by multiple threads simultaneously without causing data corruption or inconsistencies.
49What is a thread-safe counter?A thread-safe counter is a variable that can be safely incremented or decremented by multiple threads without causing data corruption.