Concurrency and Synchronization Flashcards
What is concurrency in operating systems?
Concurrency is the execution of multiple processes or threads at the same time, either by interleaving on a single CPU or overlapping on multiple CPUs.
What is the main benefit of concurrent execution?
It allows efficient utilization of resources and faster execution of multiple tasks.
What are shared resources in the context of concurrency?
Shared resources are data or devices that multiple threads or processes can access, such as variables, memory, or files.
What is a race condition?
A race condition occurs when multiple threads/processes access and modify shared data concurrently, leading to unpredictable outcomes.
What is required for a race condition to occur?
At least one access must be a write, and the accesses are not mutually exclusive.
What is a critical section?
A critical section is a part of the program that accesses shared resources and must not be executed by more than one thread/process at a time.
What is mutual exclusion?
Mutual exclusion ensures that only one thread/process can access the critical section at a time.
List the three requirements for mutual exclusion.
Mutual Exclusion, Progress, and Bounded Waiting.
What is a deadlock?
A deadlock is a situation where two or more processes are each waiting for the other to release a resource, and thus none proceed.
What are the four necessary conditions for a deadlock?
Mutual Exclusion, Hold and Wait, No Preemption, Circular Wait.
What is livelock?
Livelock is when two or more processes continuously change state in response to each other without making progress.
What is starvation in operating systems?
Starvation occurs when a process waits indefinitely to access a resource because others with higher priority keep getting access.
How can starvation be avoided?
By using aging and fair scheduling algorithms like priority queues.
What is the Dining Philosophers Problem?
A classic synchronization problem where philosophers must share limited forks (resources) and avoid deadlock and starvation while eating and thinking.
What is the N-1 resource allocation solution for the Dining Philosophers Problem?
Only allow N-1 philosophers to pick up forks at a time to ensure at least one can eat.
What is the resource hierarchy solution for the Dining Philosophers Problem?
Assign numbers to forks and require philosophers to pick them up in order, preventing circular wait.
What is a semaphore?
A semaphore is a synchronization primitive used to control access to a shared resource via an integer counter.
What are the key operations of a semaphore?
Initialize, SemWait (decrement, may block), SemSignal (increment, may unblock).
What is a binary semaphore?
A semaphore with an initial value of 1, also known as a mutex, allowing only one thread/process access at a time.
How does SemWait work?
It decrements the semaphore. If the value becomes 0, the process blocks until it’s incremented.
How does SemSignal work?
It increments the semaphore and unblocks a waiting process, if any.