Which of the following algorithms is used to solve the critical section…
2022
Which of the following algorithms is used to solve the critical section problem for n processes?
- A.
Peterson's algorithm
- B.
Moore algorithm
- C.
Banker's algorithm
- D.
Bakery algorithm
Attempted by 260 students.
Show answer & explanation
Correct answer: D
Concept
The critical-section problem requires a synchronization mechanism that guarantees three properties for processes sharing a resource: mutual exclusion (at most one process inside the critical section), progress (a waiting process eventually enters), and bounded waiting (no starvation). A general solution must hold for an arbitrary number of processes, n, not just two.
Applying it here
The Bakery algorithm (Lamport, 1974) gives a classic software solution that works for any number of processes n. Each process that wants to enter the critical section draws a numbered token, much like customers taking tickets at a bakery counter. The process holding the lowest token enters first; ties are broken deterministically by process id. Because every entrant gets a strictly ordered ticket, mutual exclusion, progress, and bounded waiting all hold for n processes without special hardware.
Why the other choices fail
Peterson's algorithm: a correct critical-section solution, but defined only for exactly two processes; it does not generalise to n processes on its own.
Moore algorithm: there is no established critical-section technique by this name; it is more commonly associated with the Moore finite-state-machine model in sequential-circuit and automata theory, unrelated to process synchronization.
Banker's algorithm: a deadlock-avoidance method that decides whether a resource request keeps the system in a safe state; it does not provide mutual exclusion for a critical section.