Abstract
Chapter 2 defined a simple lock service for user threads 0, …, N − 1 and a program that implements the service. That implementation assumed only read-write atomicity and weak fairness, but it had an “arbiter” thread that continuously scanned for user requests. This chapter presents a program that implements the simple lock service for two threads without resorting to an arbiter thread. The program uses Peterson’s algorithm, the simplest known solution to the classical mutual exclusion problem for two threads. (The classical mutual exclusion problem is as follows. Given a program that has “critical sections” and is executed concurrently by N threads, to obtain “entry” and “exit” procedures to surround each critical section such that (1) at most one thread is inside a critical section at any time, and (2) any thread that starts the entry procedure eventually enters its critical section provided no thread stays indefinitely inside a critical section.)
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
References
E.W. Dijkstra, Cooperating sequential processes. Technical report, Burroughs, Nuenen, The Netherlands, 1965. EWD-123
E.W. Dijkstra, Solution of a problem in concurrent programming control. Commun. ACM 8(9), 569 (1965). doi: 10.1145/365559.365617. http://doi.acm.org/10.1145/365559.365617
M.A. Eisenberg, M.R. McGuire, Further comments on dijkstra’s concurrent programming control problem. Commun. ACM 15(11), 999 (1972). doi: 10.1145/355606.361895. http://doi.acm.org/10.1145/355606.361895
L. Lamport, A new solution of dijkstra’s concurrent programming problem. Commun. ACM 17(8), 453–455 (1974). doi: 10.1145/361082.361093. http://doi.acm.org/10.1145/361082.361093
G.L. Peterson, Myths about the mutual exclusion problem. Inf. Process. Lett. 12(3), 115–116 (1981)
G. Taubenfeld, The black-white bakery algorithm and related bounded-space, adaptive, local-spinning and fifo algorithms, in DISC (Association for Computing Machinery, New York, 2004), pp. 56–70
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2013 Springer Science+Business Media New York
About this chapter
Cite this chapter
Shankar, A.U. (2013). Lock Using Peterson’s Algorithm. In: Distributed Programming. Springer, New York, NY. https://doi.org/10.1007/978-1-4614-4881-5_9
Download citation
DOI: https://doi.org/10.1007/978-1-4614-4881-5_9
Published:
Publisher Name: Springer, New York, NY
Print ISBN: 978-1-4614-4880-8
Online ISBN: 978-1-4614-4881-5
eBook Packages: Computer ScienceComputer Science (R0)