What is process synchronization?
A mechanism that ensures orderly execution of cooperating processes that share data to prevent inconsistencies.
Why is synchronization necessary?
Because concurrent access to shared data can cause race conditions, leading to inconsistent results.
What is a race condition?
When two or more processes access shared data simultaneously and the final result depends on the order of execution.
What is a critical section?
A section of code where shared resources are accessed or modified; only one process should execute it at a time.
What is the critical section problem?
The challenge of designing a protocol so that no two processes execute in their critical sections simultaneously.
What are the three requirements for a critical section solution?
Mutual Exclusion, Progress, and Bounded Waiting.
Define Mutual Exclusion.
If one process is executing in its critical section, no other process can enter its critical section.
Define Progress.
If no process is in its critical section, the selection of the next process cannot be postponed indefinitely.
Define Bounded Waiting.
A limit must exist on how long a process waits before entering its critical section after requesting it.
What is a remainder section?
The part of the program outside the critical section.
What is Peterson’s Solution?
A software solution for mutual exclusion between two processes using shared variables flag[] and turn.
What are the shared variables in Peterson’s Solution?
flag[i] and turn, where flag[i]=true indicates process i wants to enter its critical section.
What ensures mutual exclusion in Peterson’s Solution?
Both processes cannot have turn at the same time; only one enters its critical section.
Does Peterson’s solution satisfy all three requirements?
Yes – it ensures mutual exclusion, progress, and bounded waiting.
What is a mutex lock?
A hardware/software mechanism that enforces mutual exclusion by allowing only one thread to hold the lock at a time.
What are the two operations of a mutex lock?
acquire() and release() (or pthread_mutex_lock() and pthread_mutex_unlock()).
What is busy waiting?
When a process repeatedly checks if a lock is available, wasting CPU time (also called a spinlock).
Why are mutex locks called spinlocks?
Because a thread spins in a loop while waiting for the lock to be available.
What is a semaphore?
An integer synchronization variable used to control access to shared resources through atomic operations wait() and signal().
What is a binary semaphore?
A semaphore with values 0 or 1, equivalent to a mutex lock.
What is a counting semaphore?
A semaphore that can take non-negative integer values, used to count available resources.
What does wait(S) do?
Decrements the semaphore; if the result is negative, the process blocks itself.
What does signal(S) do?
Increments the semaphore; if the result is <= 0, a blocked process is resumed.
What is the drawback of simple semaphore implementation?
It can still cause busy waiting.