Unit 3: Process Synchronization and Deadlocks Flashcards
What is process synchronization?
Process synchronization is necessary to manage concurrently executing processes that share common resources.
It helps to avoid conflicts and ensure data consistency.
What is a race condition?
A race condition occurs when multiple processes access and modify shared data concurrently, and the final outcome depends on the order of execution.
This can lead to unpredictable results.
How can incrementing and decrementing a shared counter lead to a race condition?
Incrementing (counter++) and decrementing (counter–) a shared counter by multiple processes can lead to an incorrect final value due to interleaving.
Interleaving refers to the overlapping execution of processes.
What is a critical section?
A critical section is a segment of code where a process accesses shared resources.
Proper management of critical sections is essential to avoid race conditions.
What is the goal of the critical section problem?
The goal of the critical section problem is to design protocols that allow processes to access shared resources safely and avoid race conditions.
What is mutual exclusion?
Mutual exclusion is a requirement for critical section solutions, ensuring that only one process can be in its critical section at a time.
What does progress mean in the context of critical sections?
Progress is a requirement, stating that if no process is in its critical section and some want to enter, the decision of who enters next cannot be postponed indefinitely.
What is bounded waiting?
Bounded waiting is a requirement, ensuring a limit on how many times other processes can enter their critical sections after a process has requested to enter its own.
What is Peterson’s solution?
Peterson’s solution is a software-based solution to the critical section problem for two processes, using shared flag and turn variables.
In Peterson’s solution, what does flag[i] = true indicate?
flag[i] = true indicates that process Pi is ready to enter the critical section.
What does the turn variable indicate in Peterson’s solution?
The turn variable indicates whose turn it is to enter the critical section.
What are atomic operations?
Atomic operations are hardware support instructions that are non-interruptible and help solve the critical section problem.
What does the test_and_set() instruction do?
test_and_set() atomically tests and sets a boolean value, returning the original value.
How can test_and_set() be used for mutual exclusion?
test_and_set() can be used with a shared lock variable to enforce mutual exclusion by busy-waiting until the lock is false.
What does the compare_and_swap() instruction do?
compare_and_swap() atomically compares a value with an expected value, and if they are equal, sets the value to a new value, returning the original value.
How can compare_and_swap() be used for mutual exclusion?
compare_and_swap() can be used with a shared lock variable to enforce mutual exclusion by busy-waiting until the lock is 0.
What is a semaphore?
A semaphore is a synchronisation tool (integer variable) accessed only through atomic wait() and signal() operations.
What does the wait() operation do in semaphore?
The wait(S) operation decrements the semaphore value S, and if S becomes non-positive, the process may be blocked.
What does the signal() operation do in semaphore?
The signal(S) operation increments the semaphore value S, potentially waking up a blocked process.
What is a counting semaphore?
A counting semaphore can have an integer value over an unrestricted domain, used for controlling access to a finite number of resources.
What is a binary semaphore?
A binary semaphore can only have values 0 or 1, functioning similarly to a mutex lock for mutual exclusion.
How can semaphores ensure order of execution?
Semaphores can ensure one statement (S1 in P1) happens before another (S2 in P2) by initialising a semaphore to 0 and using signal() after S1 and wait() before S2.
What is deadlock?
Deadlock is a situation where two or more processes are blocked indefinitely, each waiting for a resource held by another process in the set.
What is the mutual exclusion condition for deadlock?
Mutual exclusion is a condition for deadlock, where resources are non-sharable, and only one process can use a resource at a time.