Non-Blocking K-Compare Single Swap

Non-Blocking K-Compare Single Swap

Nonblocking k-compare-single-swap Victor Luchangco Mark Moir Nir Shavit Sun Microsystems Laboratories Sun Microsystems Laboratories Tel Aviv University 1 Network Drive 1 Network Drive Tel Aviv 69978, Israel Burlington, MA 01803, USA Burlington, MA 01803, USA [email protected] [email protected] [email protected] ABSTRACT 1. INTRODUCTION The current literature offers two extremes of nonblocking The implementation of concurrent data structures is much software synchronization support for concurrent data struc- easier if one can apply atomic operations to multiple memory ture design: intricate designs of specific structures based on locations [7]. Current architectures, however, support ato- single-location operations such as compare-and-swap (CAS), mic operations only on small, contiguous regions of memory and general-purpose multilocation transactional memory im- (such as a single or double word) [6, 18, 27, 29]. plementations. While the former are sometimes efficient, The question of supporting multilocation operations in they are invariably hard to extend and generalize. The lat- hardware has in recent years been a subject of debate in ter are flexible and general, but costly. This paper aims at a both industrial and academic circles. Until this question is middle ground: reasonably efficient multilocation operations resolved, and to a large extent to aid in its resolution, there is that are general enough to reduce the design difficulties of an urgent need to develop efficient software implementations algorithms based on CASalone. of atomic multilocation operations. We present an obstruction-free implementation of an The current literature (see the survey in Section 5) offers atomic k-location-compare single-swap (KCSS) operation. two extremes of software support for concurrent data struc- KCSS allows for simple nonblocking manipulation of linked ture design. On one hand, there are intricate designs of data structures by overcoming the key algorithmic difficulty specific constructs based on single-location synchronization in their design: making sure that while a pointer is be- primitives such as compare-and-swap (CAS). On the other ing manipulated, neighboring parts of the data structure hand, there are general-purpose implementations of multi- remain unchanged. Our algorithm is efficient in the com- location software transactional memory. While the former mon uncontended case: A successful k-location KCSS oper- lead to efficient designs that are hard to extend and gener- ation requires only two CASoperations, two stores, and 2 k alize, the latter are very general but costly. This paper aims noncached loads when there is no contention. We therefore at the middle ground: reasonably efficient multilocation op- believe our results lend themselves to efficient and flexible erations that offer enough generality to reduce the design nonblocking manipulation of list-based data structures in difficulties of algorithms based on CASalone. today’s architectures. 1.1 K-compare single-swap 1 Categories and Subject Descriptors We present a simple and efficient nonblocking implemen- tation of an atomic k-location-compare single-swap (KCSS) D.1.3 [Programming Techniques]: Concurrent Program- operation. KCSS verifies the contents of k locations and ming modifies one of them, all as a single atomic operation. Our KCSS implementation, when executed without contention, General Terms requires only two CASoperations, two stores, and 2 k non- cached loads. It requires no memory barriers under the TSO Algorithms, Theory memory model [29]. As we show, this compares favorably with all implementations in the literature. Keywords The nonblocking progress condition our implementation meets is obstruction-freedom. Obstruction-freedom is a new Multiprocessors, nonblocking synchronization, concurrent progress condition, proposed by Herlihy, Luchangco, and data structures, linked lists, obstruction-freedom Moir [14] to simplify the design of nonblocking algorithms by removing the need to provide strong progress guarantees in the algorithm itself (as required by wait-freedom or lock- Permission to make digital or hard copies of all or part of this work for freedom [11]). Simply put, obstruction-freedom guarantees personal or classroom use is granted without fee provided that copies are a thread’s progress if other threads do not actively interfere not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to for a sufficient period. The definition is thus geared towards republish, to post on servers or to redistribute to lists, requires prior specific 1 permission and/or a fee. We use “nonblocking” broadly to include all progress condi- SPAA’03, June 7–9, 2003, San Diego, California, USA. tions requiring that the failure or indefinite delay of a thread Copyright 2003 Sun Microsystems, Inc. All rights reserved. not prevent other threads from making progress, rather than ACM 1-58113-661-7/03/0006 ...$5.00. as a synonym for “lock-free”, as some authors prefer. 314 P: delete(b) a 1 b 3 c 3 d 6 ...CAS(&a.next,b,d)... a b d if count > 0, increment or decrement using CAS Q: insert(c) c ...CAS(&b.next,d,c)... Problem: node c not inserted a 1 b 3 c 3 e 4 P: delete(b) insert node with count = 1 using 2CSS d 1 ...CAS(&a.next,b,c)... a b c d Q: delete(c) a 1 b 3 c 0 d 6 ...CAS(&b.next,c,d)... Problem: node c not deleted remove node with count = 0 using 4CSS Figure 1: CAS-based list manipulation is hard (the examples slightly abuse CAS notation). In both ex- Figure 2: Illustration of a KCSS-based multiset im- amples, P is deleting b from the list. In the upper plementation. Each element in the multiset (i.e., an example, Q is trying to insert c into the list, and in element with nonzero multiplicity) is represented by the lower example, Q is trying to delete c from the a node in the list, which stores the element’s mul- list. Circled locations indicate the target addresses tiplicity in a count field. Inserts or deletes of such of the CAS operations; crossed out pointers are the elements respectively increment or decrement the values before the CAS succeeds. count (top figure). Two- and four-location KCSS op- erations are used to add and remove nodes by swap- ping one pointer, while confirming nearby nodes the uncontended case, handling contended cases through or- have not changed (middle and bottom). thogonal contention management mechanisms. (Contention management mechanisms similar in spirit to the ones dis- cussed in [15] are applicable to the algorithms presented and novel implementation of load-linked/store-conditional here; we do not discuss contention management further in (LL/SC) using CAS; this implementation improves on pre- this paper.) Lock-based algorithms are not obstruction-free vious results in that it can accommodate pointer values on because a thread trying to acquire a lock can be blocked all common architectures. We believe this algorithm is of indefinitely by another thread that holds the lock. On the independent value: it extends the applicability of LL/SC- other hand, any lock-free algorithm is also obstruction-free based algorithms to all common architectures that support because lock-freedom guarantees progress by some thread if CAS. This answers a question that remained open following some thread continuously take steps. the work of Moir [24]. 1.2 Manipulating linked data structures Section 2 defines the semantics of the operations for which we present implementations in Section 3. In Section 4, we KCSS is a natural tool for linked data structure manip- discuss various optimizations, generalizations, and exten- ulation; it allows a thread, while modifying a pointer, to sions that are possible. In Section 5, we survey previous check atomically that related nodes and pointers have not work on multilocation synchronization. We conclude in Sec- changed. An application of immediate importance is the tion 6. A correctness proof appears in the appendix. implementation of nonblocking linked data structures with arbitrary insertions and deletions. As Figure 1 shows, naive approaches to implementing nonblocking insertion and dele- 2. PRELIMINARIES tion operations for a linked list using single-location CASdo A k-location-compare single-swap (KCSS) operation takes not work. Although there exist effective (and rather inge- k locations a1..ak, k expected values e1..ek,andanewvalue nious) nonblocking algorithms for ordered list-based sets [8, n1. If the locations all contain the expected values, the 21], these algorithms do not generalize easily to arbitrary KCSS operation atomically changes the first location a1 linked data structures. For example, it is not clear how to from e1 to n1 and returns true; in this case, we say that modify these algorithms to implement multisets. the KCSS succeeds. Otherwise, the KCSS returns false and By employing KCSS instead of CAS, we can simplify the does not modify any memory location; in this case we say design of arbitrary nonblocking linked-list operations. For that it fails. In the next section, we present an implemen- example, Figure 2 illustrates how the use of KCSS can sig- tation for KCSS using special read, load-linked (LL), store- nificantly simplify the design of a linked-list construct to conditional (SC) and snapshot operations that we have also support multiset operations (details of the illustrated algo- implemented. In this section, we describe more precisely rithms are beyond the scope of this paper). For simplic- the interface and semantics of the various operations, the ity, the illustrated implementation uses a 4CSS operation correctness requirements, and our assumptions about the to make sure the adjacent nodes have not changed during system. node removal; we can achieve the same purpose using KCSS operations that access only two locations at the cost of a 2.1 Semantics of operations slightly more intricate algorithm.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us