Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Lockless Algorithms

The other approach to lockless algorithms is to code the algorithms so that they do not require locks. This can be complicated to achieve because it requires consideration of the state of the data and the transitions between data states to ensure that the system remains in legal states all the time.

Dekker’s Algorithm

One of the first lockless algorithms was Dekker’s algorithm for mutual exclusion. Without using any atomic operations, the algorithm ensures that only one thread at a time out of a pair of threads can enter a critical region. Listing 8.16 shows an implementation of Dekker’s algorithm. To increment the counter a thread would call the function increment() with its thread ID.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint