Skip to main content

Lock Using Peterson’s Algorithm

  • Chapter
  • First Online:
Distributed Programming
  • 1525 Accesses

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.)

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 54.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

References

  1. E.W. Dijkstra, Cooperating sequential processes. Technical report, Burroughs, Nuenen, The Netherlands, 1965. EWD-123

    Google Scholar 

  2. 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

    Google Scholar 

  3. 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

    Google Scholar 

  4. 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

    Google Scholar 

  5. G.L. Peterson, Myths about the mutual exclusion problem. Inf. Process. Lett. 12(3), 115–116 (1981)

    Article  MATH  Google Scholar 

  6. 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

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints 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)

Publish with us

Policies and ethics