WorksComputer Science
Making History-Independence-Preserving LL/SC Writable
Abstract
A randomized implementation of LL/SC objects for processes, with at most outstanding LL() operations each, uses CAS and FAID objects [Bencivenga, Habashi, and Woelfel, DISC 2026], achieves constant expected step complexity, and preserves quiescent history independence for algorithms such as [Hagit Attiya, Michael A. Bender, Martín Farach-Colton, Rotem Oshman, and Noa Schiller, STOC 2025]. Unlike some other LL/SC algorithms, such as [Anderson and Moir, WDAG 1995; Jayanti and Petrovic, PODC 2003; Jayanti, Jayanti, and Jayanti, DISC 2023; Hagit Attiya, Michael A. Bender, Martín Farach-Colton, Rotem Oshman, and Noa Schiller, PODC 2024], this algorithm does not support an unconditional write operation. We show how to add a (randomized) wait-free write operation without affecting the asymptotic step or space complexity of the implementation.
2012 ACM Subject Classification Theory of computation → Shared memory algorithms; Theory of computation → Design and analysis of algorithms; Theory of computation → Concurrent algorithms
Keywords and phrases writable LL/SC, concurrent algorithms, history independence, randomized algorithms, wait-freedom
Funding Dante Bencivenga: Natural Sciences and Engineering Research Council of Canada (NSERC) Canada Graduate Scholarship – Doctoral (CGS-D) 578918-2023/198 and University of Calgary Eyes High Doctoral Recruitment Scholarship
Philipp Woelfel: Natural Sciences and Engineering Research Council of Canada (NSERC) reference number RGPIN-2025-04233
Introduction
Asynchronous shared memory algorithms generally require the use of atomic hardware instructions in order to coordinate their actions. Several such instructions are now standard in modern processors, such as swap, compare-and-swap, and fetch-and-add: The swap instruction writes a value into a shared memory word and returns its immediately preceding value. The compare-and-swap, or CAS(old, new), instruction only takes effect if the shared memory word stores an expected old value, in which case it replaces it with new. In this paper, we only need CAS() to return a Boolean indicating success or failure, but it can sometimes return the previous value like a Swap() call. The fetch-and-add instruction adds a given integer value to the value stored in a shared memory word, returning the previous value. In this paper, we need only use fetch-and-add to add or subtract one, which we call fetch-and-increment (FAI()) and fetch-and-decrement (FAD()) respectively.
Although CAS() together with read/write registers is already sufficient to implement any shared object with a sequential specification [21], it can be difficult to use correctly due to the ABA problem. For example, suppose a shared memory object stores value , is read by a process, and then the process attempts a CAS() from to . The process has no way of knowing whether the object’s value stayed at in between the read and CAS(), or if it changed to and back in between. This ambiguous situation is the ABA problem, and it can easily lead to incorrect changes to data structures if not handled carefully.
The LL/SC object fixes this problem by the use of two operations. The load-linked (LL()) operation reads and returns the object’s value. The store-conditional (SC(v)) operation can succeed or fail: It succeeds and writes a value to the object if and only if no Write() or successful SC() took place since the preceding LL(). Otherwise, it fails (see § 2.3 for a more formal specification). Therefore, it prevents the ABA problem, hence avoiding a large class of bugs that are otherwise hard to identify and correct. Most implementations, including ours, also include a verify-link (VL()) operation, which returns a Boolean indicating whether an SC() would succeed, without changing the state of the object.
Unfortunately, LL/SC as defined here does not exist in modern hardware. (Some architectures have a pair of instructions called LL() and SC(), but their SC() operation can spuriously fail even without any change to the memory word, and the pair is strongly restricted in which operations can happen in between. These instructions are sometimes called RLL/RSC to differentiate them from ‘strong’ LL/SC; see, e.g., [26]. As such, several software implementations have been devised [3, 4, 9, 13, 15, 23, 27, 28, 29, 32, 34, 35, 36], with various properties, such as supporting a Write() operation [5, 6, 24, 25, 26], achieving strong linearizability [36], durability [25], or adapting to the number of processes in the system [15, 25, 29]. Although any LL/SC implementation can support a lock-free Write(v) operation by repeatedly calling LL() and then SC(v) until some SC(v) attempt succeeds, supporting wait-free Write() and LL/SC on the same object is more difficult.
Our implementation has optimal space and expected step complexity, uses bounded base objects, supports a Write() operation in addition to LL() and SC(), and preserves quiescent history independence, which we explain next.
History independence is a useful security property which has been heavily studied in the context of sequential computing [1, 11, 12, 14, 17, 18, 19, 20, 33, 37, 38] and recently explored in concurrent computing [6, 7, 9, 39]. Roughly, an implementation is history-independent if the state of memory in between operations is a function only of the abstract state of the implemented object(s). In the context of concurrent computing, there are several ways to define history independence, as explored in [6]. Their most stringent definition is perfect history independence, which requires that shared memory is a function of the abstract state at all points of the execution, but they show that this requires impractically large base objects for most abstract objects.
As with [9], we instead focus on quiescent history independence (QHI). A quiescent state is a system configuration in which no process is pending, i.e., no process has invoked but not yet responded from a method call. An implementation is QHI if its state of shared memory is a function of the abstract state of the concurrent object(s) during all quiescent states reachable in any execution of that implementation. Since algorithms using LL/SC generally do not require outstanding LL() operations (i.e., an LL() operation not yet followed by a matching SC() operation, which we formally define in Definition 2) in quiescent configurations, we use a relaxed definition of QHI, following [9]: We replace quiescent states in the definition of QHI with settled states, which are quiescent states with the additional property that no process has an outstanding LL() operation. The state of shared memory then needs to be a function of the abstract objects’ state during settled states of any reachable execution. An LL/SC implementation satisfying this relaxed definition, such as ours, is QHI-preserving. Any algorithm using a QHI-preserving LL/SC implementation, which does not have outstanding LL() operations while processes are idle, satisfies QHI. This is usually possible to achieve by adding “clear-link” or CL() operations before method responses, which clears outstanding LL() operations.
There are few LL/SC implementations which also provide a Write() operation with sub- space complexity, where is the number of LL/SC objects and is the number of processes. Jayanti, Jayanti, and Jayanti’s implementation [25] has constant step complexity, optimal adaptive space complexity of , where is the total number of outstanding LL() operations at a given time, and it is durable on non-volatile memory. However, it uses unbounded sequence numbers, and is therefore not suitable for history independent algorithms. The implementation of Attiya, Bender, Farach-Colton, Oshman, and Schiller [6] satisfies perfect history independence, but uses large base objects of size bits and is only lock-free.
Other papers give transformations to add a Write() operation to existing LL/SC implementations: Jayanti [24] gave a transformation to obtain a writable LL/SC object from two non-writable LL/SC objects, attaching constant-size tags to the objects’ values. However, because the algorithm’s correctness requires these tags to not be reset in quiescent states, the transformation does not preserve history independence. Another, more general, transformation by Aghazadeh, Golab, and Woelfel adds unconditional Write() operations to shared objects [2], and Ben-David, Blelloch, Friedman, and Wei later optimized their space complexity [8], but their transformation increases the space by additional base objects. Moreover, their transformation also does not preserve history independence, unlike our implementation.
Our implementation is based on that of Bencivenga, Habashi, and Woelfel [9], which has the above features but without a Write() operation. The addition of a randomized wait-free Write() operation and a new correctness analysis are the main technical contributions of this paper. Our Write() operation can also naturally be used as a Swap() operation because it internally linearizes at a hardware Swap() operation (which is not used in [9]).
Other papers give transformations to add a Write() operation to existing LL/SC im- plementations: Jayanti [24] gave a transformation to obtain a writable LL/SC …
Theorem 1. Let be the number of processes and be the maximum number of simultaneously outstanding LL() operations per process. Then there is a linearizable and QHI-preserving implementation of LL/SC objects from CAS/Swap objects, storing LL/SC values plus tags of bits, and FAID/CAS objects of bits. The implementation supports the implemented methods LL(), SC(), Write(), Swap(), CL(), Read(), and VL(), with expected step complexity under the weak adaptive adversary.
Because our implementation uses more base objects, larger tags, and more steps per implemented method than [9], while also using a wider variety of primitive operations, their implementation is preferable when unconditionally writing to LL/SC objects is not required.
Like the implementation of [9], we attach bounded tags to each CAS object that implements an LL/SC word, of size bits. As [9, 13] argue, is at most 3 in published algorithms using LL/SC, thus making our tags of at most bits in practice. Since 64-bit heap pointers generally have the high 16 bits and low 3 bits set to zero [30], this allows a pointer to be stored with 19 tag bits into one 64-bit word. As a result, our implementation can be used to store pointer values in LL/SC objects if the number of processes is up to , which matches the default maximum number of processes and threads on Linux [31].
The additional complexity needed to support unconditional wait-free Write() arises in part because it becomes more difficult to correctly choose a new tag to prevent ABAs. In particular, [9] counts how many processes have an outstanding LL() operation which have seen each tag value in FAID objects, and SC() randomly probes these usage counts to find a tag with a usage count of zero. This works in part because a successful SC() must be preceded by an LL() operation, and therefore the previous tag has a nonzero usage count, ensuring that a successful SC() always changes the tag. However, an unconditional Write() operation has no such prerequisite, so a further mechanism is needed to ensure that it always changes that tag, so that concurrent SC() operations can fail. As such, our usage counts additionally count how many LL/SC objects are currently using a given tag. SC() and Write() calls attempt a CAS() from zero to one on a randomly probed usage count, and then keep the usage count incremented until the LL/SC object no longer stores that tag. This makes tracking usage counts more complicated, since the responsibility for decrementing them can shift to a different process, and it affects several other aspects of the analysis.
The remainder of the paper is structured as follows: Section 2 defines the shared-memory model and the specification of writable LL/SC, Section 3 presents our implementation and intuitive explanations for it, Section 4 proves Theorem 1, and Section 5 concludes the paper.
Preliminaries
We use the standard asynchronous shared memory model, where processes communicate by performing atomic shared-memory operations on shared objects. At each point in time of the execution (which we refer to simply as a ‘point’), exactly one shared memory operation takes place.
Primitive Operations
The atomic primitive operations we use are Read(), CAS(), FAI(), FAD(), and Swap(). The Read() operation returns the value of the shared object. The Swap(val) operation writes into the shared object, and returns its previous value. The CAS(old,new) operation writes into the shared object and returns True if and only if its previous value was , and otherwise leaves the object unchanged and returns False. Finally, the FAI() and FAD() increment or decrement the object’s (integer) value, respectively, and returns the previous value. In our analysis, we initially assume that a FAI() on value wraps to back to 0, and similarly that a FAD() on 0 wraps it to . We prove (Lemma 7 and Lemma 12(a)) that overflow and underflow never occur on the FAID objects, and therefore those objects can have any overflow and underflow behaviour (including having a larger range of possible values before overflowing).
The objects in our implementation require the combinations Read(), CAS(), and Swap() for elements of an array , Read(), FAI(), and FAD() for elements of an array , and FAI(), FAD(), and CAS(0, 1) for elements of an array . (In practical implementations, all shared memory variables generally support the same set of atomic hardware instructions, which commonly include all the ones used in this paper.)
Adversary
Our algorithm is randomized, meaning that at any point a process can generate a (private) random number by performing a random choice step. The adversary determines the order in which processes take steps, by deciding at any point during the execution, the next process to take a step. We assume the same adversary used in [9], the weak adaptive adversary, where a process always performs its next shared memory operation immediately after a random choice step. I.e., while the weak adaptive adversary knows all past random choices and adapts to them, it cannot intervene between a process’s random choice and its following shared-memory step. Even though we employ randomization, all correctness properties such as linearizability [22] and preserving quiescent history independence (QHI) are achieved deterministically, i.e., they hold for all executions, regardless of the random choices made.
Sequential Specification
This section closely follows Section 2.1 of [9], with all operations other than Write() defined in the same way as in that paper.
An abstract object (also known as type) is a quintuple , where is a set of states, is the initial state, and are sets of operations and responses, respectively, and is the transition function. This quintuple is also called the sequential specification of the object, as it defines the set of possible sequential executions: Whenever an object is in state and operation is invoked, defines the operation’s response and resulting new state .
To specify the abstract object writable LL/SC, we follow the definitions in [6, 9, 25]. Each state is a pair , where is the object’s value and is an -bit sequence , called context. Initially, , and the initial value of can be defined arbitrarily. We say that has an open link to the LL/SC object whenever .
A Read() returns the value of the object. An LL() (“load-linked”) call by process sets to 1 and returns the value . A Write(x) operation by process unconditionally changes the state of the object to and does not return anything. An SC(x) (“store-conditional”) operation by process succeeds if , in which case it changes the state of the object to (like Write(x)) and returns True. If , then the operation fails and returns False without changing the state of the object. Operation CL() (“clear link”) by process simply resets to 0, and does not return anything. Finally, operation VL() (“verify link”) by process returns a Boolean value that is true if and only if $\ell_p = 1.
In this paper, we implement a collection of writable LL/SC objects, and refer to the -th such object as . Thus, the abstract object’s state is the cross product of the states of individual LL/SC objects. As such, each operation has one additional parameter that indicates which of the LL/SC objects in the collection is affected. For example, operation Write(i, x) behaves as the Write(x) operation defined above, affecting only , the -th LL/SC object in the collection.
Outstanding LL() Operations
Our implementation requires knowledge of the number of processes and the number of outstanding LL() operations per process, which we formally define next:
Definition 2 (Outstanding LL() Operation). A process has an outstanding LL() operation on at point if and only if
has no pending method call on at point , and
has called
LL(i)before point without having subsequently invoked aWrite(i, ·),SC(i, ·), orCL(i)call, or aVL(i)call that returns False.
Equivalently, we say that has an outstanding LL(i) at point .
The definition of outstanding LL() operations is similar to that of [9], except that calls to Write(i, ·) clears any outstanding LL(i), and we do not consider a process with a pending call on to have an outstanding LL(i).
In our implementation, is a per-process bound on the number of outstanding LL() operations (as opposed to a global bound, as in [9]). As such, we require that when LL(i) is called, the calling process has fewer than outstanding LL() operations to objects other than .
As with [9], our implementation requires that processes clear their outstanding LL(i) operations with CL(i) if they are no longer needed before returning from methods, in order to achieve our space bounds and preserve QHI.
Implementation
Intuition for Changes from Non-Writable QHI-Preserving LL/SC
At a very high level, the non-writable LL/SC implementation of [9] works by storing the value of the -th LL/SC object, , together with a non-negative bounded tag in an array entry .
An array has one element per nonzero tag : stores the usage count of tag , which is the number of outstanding LL() operations that have read tag from the tag field of some element of . (Tag zero is the default value, and as such is treated differently, including not needing a usage count.) An LL(i) call increments if it reads that . A nonzero usage count signals that a process has protected that tag, and that it should not be reused while protected. An SC(i, ·) call randomly probes elements of until it finds a new tag such that it reads . A usage count of zero indicates that is not protected, and it is hence safe to change to without causing an ABA problem. Any operation that clears an outstanding LL() operation then decrements the usage count of its associated tag.
Another array has one element per LL/SC object: stores the activity count of , which is the number of processes with a pending method call on or that have an outstanding LL(i). When reaches zero, it is safe (and necessary for preserving QHI) to reset to zero, since there is no outstanding and therefore no ABA problem to guard against. A nonzero activity count can thus be roughly thought of as protecting tag zero from being used in non-quiescent states.
For more thorough explanations, see the high- and low-level descriptions in § 3 of [9].
We now explain the motivation for how to change the algorithm of [9] to allow for randomized wait-free Write() operations, and the necessary changes required to maintain correctness, the same asymptotic step and space complexity, and to preserve quiescent history independence.
The primary difference in our implementation from that of [9] is in how we manage the usage counts in array . As with [9], when a process performs LL(i) on LL/SC object and sees a nonzero tag , it increments usage count . (The default tag zero does not have a usage count, and its ABA prevention comes from activity counts in array ).
Recall that in [9], an SC(i, ·) call randomly probes elements of until it reads zero for some —this implies that, at the time of the read, tag is not protected. However, it is possible that tag becomes protected by the time the SC() call attempts a CAS() on , which if successful would change to the protected tag , thus potentially causing an ABA problem. But, a process only protects tag if it sees that , implying that changes before the attempted CAS() on . Moreover, the process calling SC(i, ·) is itself protecting a tag from its own outstanding LL(i) that it read from . It uses tag in its CAS attempt, i.e., the CAS() is from to . Thus, the only way for the CAS() to succeed is if changes from to and back to , i.e., by an earlier ABA. Since SC() is the only method in their implementation which can modify , and since it cannot cause the first ABA, it follows that it cannot cause any ABA (see their Lemma 17). Crucially, their argument relies on only SC() calls modifying , and that is only modified via CAS() operations.
Like SC(i, ·), an added Write(i) operation should also choose a new tag that no processes’ currently outstanding LL(i) has seen, in order to prevent ABAs for those processes’ SC(i, ·) operations. Unlike SC(), however, Write() always succeeds and does not require a preceding LL(), while still being (randomized) wait-free. This means that simply verifying that a usage count is zero is no longer sufficient: A process executing a Write(i, ·) operation could fall asleep after reading , after which tag could become used in from another SC(i, ·) or Write(i, ·) operation. Since we require that Write() is a randomized wait-free method which unconditionally updates , there must be some step in its operation in which it updates with some nonzero probability, along with updating to a new, unprotected tag. But since a Write() call does not know that is still unprotected before its update to after having only read that , any such update to can potentially lead to ABAs. (In contrast, an SC() attempts a CAS(), and this is guaranteed to fail if had changed, as argued earlier.)
Instead, our approach is for to prevent its chosen tag from being used by any concurrent Write() or SC() operation by replacing a read of zero with an operation. This effectively locks the tag for exclusive use by until is eventually decremented back to zero. Following [9], we assume that processes are scheduled by the weak adaptive adversary which cannot intervene in between a random choice and the next shared-memory step. Thus, after a random choice of a new tag , we immediately follow it by an attempt, which succeeds with constant probability as long as we have sufficiently many unused tags to choose from. We call such a successful CAS() on locking tag by the calling process (this lock does not compromise randomized wait-freedom, since our algorithm guarantees a constant success probability with each randomly probed tag). A Write(, ) call can then unconditionally write this new tag and its value into . We also need to prevent Write() calls from using the same tag chosen by concurrent SC() calls, which can cause ABA’s due to the unconditional nature of Write(): We therefore change the SC() method to attempt a CAS(0, 1) for each randomly selected tag until it succeeds, exactly like the Write() method.
In order to ensure history independence and allow for eventual safe recycling of tags, this additional increment of must eventually be decremented before the system enters a quiescent state. In the case of a failed SC() operation, the calling process can safely decrement the usage count for its selected tag immediately, since it is not used anywhere else.
However, consider what happens if we decrement at the end of a Write(, ·) or successful SC(, ·) call. If some other crashed process keeps , indicating a non-quiescent state, then is not reset to zero, in which case we could have and when a Write() or SC() call responds. This scenario is not a problem in [9], when only SC() operations can change LL/SC objects. In our case, however, a new Write() call could re-lock tag , reaching a configuration with a pending Write() operation poised to write back into , while . This scenario violates the sequential specification, because Write(, ·) should set all context bits of to zero, causing concurrent SC(, ·) operations to fail; writing back the same value-tag pair is instead invisible to all other processes. Also, a Write(, ·) call poised to overwrite could revert a changed value-tag pair, which again leads to an undetected ABA, invisible to concurrent LL() operations regardless of which tags they protect.
While it is tempting to have Write() calls simply double-check that after locking , this would in the worst case require a lock-free loop that cannot guarantee wait-freedom. (Recall that we only prevent the weak adaptive adversary from interfering in between a random choice and the immediate next step, whereas this last idea would require two shared-memory steps to be uninterrupted to achieve randomized wait-freedom.)
Due to these considerations, after locking a nonzero tag , we keep it locked for at least as long as . This implies that the responsibility to decrement shifts from the process with the Write() or successful SC() operation to the one that next changes to some other tag. After every successful CAS() operation on which changes away from , we thus add a decrement of . Since the Write() operation needs to unconditionally change and also know the previous tag stored in before overwriting it, we use the Swap() instruction to read the previous tag. Thus, the Write() method also decrements after reading nonzero from after a Swap(), without losing randomized wait-freedom.
Since Write() and SC() now increment usage counts, and the responsibility for decrementing the counts shifts to other processes, analyzing contributions to usage counts becomes more complicated. A side effect of keeping tags locked by LL/SC objects is that each object is now guaranteed to store a unique tag if it is nonzero (i.e., distinct LL/SC objects do not share the same nonzero tag). This property is not directly needed for correctness, complexity, or preserving QHI, but it does reduce the maximum value that elements of need to store to , compared to in [9].
Because objects now contribute to usage counts, it may initially appear that we need more tags, and hence more elements of , so that the choice of a random tag still succeeds with constant probability. However, recall that, to preserve QHI, we reset all tag fields to zero for each object that does not have a pending method call or an outstanding LL() operation on it. As such, we can show (Lemma 22) that every LL/SC object with a nonzero tag field is associated with some process that either has a pending method call on or has an outstanding LL(). Since there are processes and at most outstanding LL() operations, the extra number of used tags is at most . In total, including the factor of 2 to ensure that at least half of the tags are unused, nonzero tags, only a constant factor more than the nonzero tags required in [9].
This observation only holds when using the QHI-preserving version of the algorithm: as with [9], our implementation can be made simpler by dropping that requirement, but then the number of required tags becomes . Conversely, if Write is only invoked when the calling process has fewer than outstanding LL() operations, then this bound decreases slightly to . Regardless, all such variants of the implementation use total base objects.
Lastly, to preserve QHI, the Write() method must change the tag field to zero if the activity counter is zero, using the same mechanism as in [9] in their CL() method. However, since the Write() method does not involve any outstanding LL() operation, it does not need to do the bookkeeping work of clearing information related to outstanding LL() operations like in that paper’s CL() method. Since the Write() method also does not guard against an ABA problem, it has no need to increment (or decrement) the activity counter itself: It only needs to check whether the counter is zero and, if so, to try to change the LL/SC object’s tag field to zero. As such, we split CL() into a shorter CL() method plus a cleanup() method: the former handles clearing outstanding LL() operations, and the latter attempts to reset tag fields to zero before entering a quiescent state.
Low-Level Description
In this section, we present and explain the pseudocode for our implementation, including the parts that are unchanged from [9]. When the details are the same, we explain them similarly.
We store the values of the LL/SC objects in an array of CAS objects. In addition, each CAS object stores a non-negative bounded tag that is initialized to zero. The array is used to count each tag’s usage, so that counts the number of processes that have an outstanding LL() operation that read the tag , plus the number of objects with in their tag field. The purpose of usage counts is to prevent ABAs. Array is an activity counter for LL/SC objects, so that tracks how many processes have an outstanding LL(); its purpose is to detect quiescent states, and thus help preserve quiescent history independence.
In any LL/SC implementation, processes need some way to keep track of their outstanding LL() operations, in order to be able to know whether their SC() and VL() calls should succeed. Here, processes use a local dictionary , which stores, for each LL/SC object , a pair consisting of the last value and tag read from , or the empty value if the process has no outstanding LL(). (The SC(), VL(), and CL() methods each return immediately when , since they are only meaningful for a process with an outstanding LL().)
Changes or additions relative to [9] are indicated in blue. Our implementation uses tags rather than as in [9], or slightly over twice as many tags. On the other hand, in this version tags are never shared between distinct LL/SC objects, the elements in need only store values up to rather than . In addition to adding a Write() method relative to [9], we also move the tag field-resetting functionality of CL() into a new helper method called cleanup(). Since cleanup() is only a helper method, it is not called directly, and as such is not mentioned in the sequential specification.
Constants:
is the set of values that LL/SC objects can have
is the number of LL/SC objects
is the number of processes
is the maximum number of outstanding LL() operations per process
Shared Data:
for is a CAS/Swap object storing a pair in
for is a FAID object storing a number in
for is a FAID/CAS object storing a number in
Process-local static data:
is a dictionary storing keys in and values in
Initialization:
, where is an application-dependent initial value from
starts empty for each process (all indexing returns )
LL() Method
The LL() method is unchanged from that of [9].
Since processes can have at most one outstanding LL(), line 1 ensures that any previous outstanding LL() is cleared by an internal CL() call (line 15 of Write() serves a similar purpose). The calling process then increments in line 2, which announces that a process has created an outstanding LL(), and tells processes not to reset .tag to zero. Next, reads the value-tag pair stored in (line 3), and stores it in its local dictionary (line 4), to use in later SC() or VL() calls. If the tag is the default tag of zero, then the call can respond immediately (line 5), because the SC() and Write() methods do not choose tag zero as their new tag, and a nonzero prevents ABAs to tag zero. Otherwise, reads a nonzero tag and increments the corresponding usage count (line 6), then reads again to confirm that it has not changed (line 7).
If has not changed upon the second read, then we say that has successfully protected the tag from being reused (see the formal definition in Definition 15), and returns in line 8, linearizing in line 7. This protection lasts until next invokes CL(), as line 35 decrements the usage count again. As we later discuss in the SC() method, the algorithm guarantees that a tag is only reused when no process protects it.
Otherwise, has changed to a different value by the time reads it in line 7. If .tag has changed to zero, then can return once it has reverted its increment of (line 10) and updated its dictionary (line 11), again because tag zero is protected by a nonzero activity count in . Otherwise, we take advantage of the fact that an SC() is required to fail if there was an intervening Write() or SC() in between a process’s LL() and SC(). We thus retroactively set ’s LL() call’s linearization point (which defines the order of the execution’s linearization) to the first read in line 3 to satisfy the sequential specification. (Although this is a standard trick for LL/SC implementations, this retroactive linearization point prevents this LL() implementation from being strongly linearizable [16].) The CL() call in line 13 sets to (line 36), as though had no outstanding LL(), which forces ’s
LL(i ∈ {1, . . . , m})
1 if d[i] ≠ ⊥ then CL(i)
2 C[i].FAI()
3 (val, tag) ← L[i].Read()
4 d[i] ← (val, tag)
5 if tag = 0 then return val
6 R[tag].FAl()
7 (val′, tag′) ← L[i].Read()
8 if (val, tag) = (val′, tag′) then return val′
9 if tag′ = 0 then
10 R[tag].FAD()
11 d[i] ← (val′, 0)
12 return val′
13 CL(i)
14 return val
Write(i ∈ {1, . . . , m}, u ∈ U)
15 if d[i] ≠ ⊥ then CL(i)
17 repeat
18 tag′ ← independent uniform random sample from {1, . . . , 4(k + 1)n}
19 until R[tag′].CAS(0, 1) = True
20 (·, tag) ← L[i].Swap((u, tag′))
21 if tag ≠ 0 then R[tag].FAD()
22 if C[i].Read() = 0 then cleanup(i)
following SC() to fail in line 23. (In this case, still does have an outstanding LL() by definition, because the fact that the next SC() will fail is not yet directly visible by an algorithm using our LL/SC implementation.)
Write() Method
In lines 17–19 of a Write(i) call, the calling process repeatedly probes random tags in the range of possible tags. Specifically, line 18 chooses an independent and uniform random tag value in the domain of possible tags. The calling process attempts a CAS() from zero to one for the chosen tag’s usage count, and repeats this random choice if the CAS() fails, until it eventually succeeds in incrementing some usage count. There are tags, and as argued in the end of Section 3.1 and proven in Lemma 22, there are at most tags with nonzero usage count at any given time. Because the weak adaptive adversary cannot intervene between the random choice in line 18 and the CAS() attempt in line 19, each CAS() attempt succeeds with probability at least . Thus, the number of loop iterations is dominated by a geometrically distributed random variable with parameter , and thus has expectation at most 2.
With a successful R[g].CAS(0, 1) for some nonzero tag , locks so that no other Write() or SC() call can use it, and then remains locked for as long as it is used in L[i].tag. Process then calls Swap() on L[i] in line 20 to write its new value together with the locked tag , which serves as the linearization point of the method. Immediately after this point,
SC($i \in \{1,\ldots,m\}$, $u \in U$)
23 if $d[i] = \perp$ then return False
25 repeat
26 $tag' \leftarrow$ independent uniform random sample from $\{1,\ldots,4(k+1)n\}$
27 until $R[tag'].CAS(0,1) = \mathrm{True}$
28 $result \leftarrow L[i].CAS(d[i],(u,tag'))$
29 if $result = \mathrm{True}$ and $d[i].tag \ne 0$ then $R[d[i].tag].FAD()$
30 if $result = \mathrm{False}$ then $result \leftarrow L[i].CAS((d[i].val,0),(u,tag'))$
31 if $result = \mathrm{False}$ then $R[tag'].FAD()$
32 CL($i$)
33 return $result$
we say that tag is locked by , because . Since had locked its nonzero tag , and the previous value of was either previously locked by or was zero, it is guaranteed that this Swap() operation changes to a different value. This in turn guarantees that any outstanding LL() by other processes detects that the Write() has linearized, preventing undetected ABAs. Since the previous tag, returned from Swap(), is no longer used in , then decrements its usage count (in line 21) so that it can eventually be unlocked and used again once the usage count reaches zero. (If there are outstanding LL() operations by other processes which have seen tag , then they contribute to the usage count , and so the tag is not fully unlocked until each of them have called CL().)
Lastly, checks if the activity counter is zero, in which case it is safe to reset the tag to zero via a cleanup() call (line 22) to preserve QHI. Note that Write() does not increment (or decrement) , because it changes unconditionally unlike SC(), without needing ABA prevention for its own operation.
Because this method linearizes at a Swap() call, it can be transformed into a Swap() implementation by returning the previous value of read (and ignored) in line 20.
SC() Method
Line 23 ensures that an SC() call returns False in the case of the calling process not having any outstanding LL() (lines 34 of CL() and 47 of VL() serve a similar purpose). Lines 25–27 work just like lines 17–19 to lock an unprotected tag for exclusive use by the calling process. Recall that stores the previous value-tag pair read from in a previous LL() operation. Line 28 thus attempts a CAS() from the previous value-tag pair stored in to the new value (the second argument of SC()) and the newly chosen tag. Similarly to line 21, line 29 unlocks the nonzero tag previously stored in after a successful CAS() in line 28, so that it can eventually be recycled.
Although a nonzero activity counter () prevents CL() calls from resetting to zero (as we detail below), there is an edge case of a CL() call poised to clear from before a time when was incremented. As such, line 30 tries another CAS() from a tag of zero, in case was reset to zero in between the previous LL() operation’s linearization point and the CAS() attempt in line 28. If both CAS() attempts fail, then line 31 unlocks the newly chosen tag, since it was not successfully used. (In this case, the usage count immediately hits zero, since no other process would have seen the tag—line 31 could be replaced with a Write() of zero, but this is somewhat less intuitive in the code.)
The method linearizes at the point of its last CAS() attempt on in either line 28
CL($i \in \{1,\ldots,m\}$)
34 if $d[i] = \perp$ then return
35 if $d[i].\mathrm{tag} \ne 0$ then $R[d[i].\mathrm{tag}].\mathrm{FAD}()$
36 $d[i] \leftarrow \perp$
37 if $C[i].\mathrm{FAD}() = 1$ then cleanup($i$)
cleanup($i \in \{1,\ldots,m\}$)
38 $(val, tag) \leftarrow L[i].\mathrm{Read}()$
39 if $tag = 0$ then return
40 $R[tag].\mathrm{FAI}()$
41 if $L[i].\mathrm{Read}() = (val, tag)$ then
42 if $C[i].\mathrm{Read}() = 0$ then
43 if $L[i].\mathrm{CAS}((val, tag),(val, 0)) = \mathrm{True}$ then
44 $R[tag].\mathrm{FAD}()$
45 $R[tag].\mathrm{FAD}()$
or 30, then calls CL() in line 32 to clear the calling process’s outstanding LL(), and returns whether its last CAS() attempt succeeded.
CL() and cleanup() Methods
After confirming that a CL() call is nontrivial (line 34), the call ends the calling process ’s protection of a nonzero tag by decrementing that tag’s usage count (line 35) and clears ’s dictionary entry for (line 36), ending ’s outstanding LL(). Next, decrements the activity counter for (line 37), announcing that its outstanding LL() has been cleared. If the counter decrements from one to zero, then has the responsibility to reset to ensure QHI, which it does via the cleanup() method.
Method cleanup() is called by either CL() as just explained, when is decremented to zero, or by Write() (line 22) when reading zero from . In both cases, the calling process has (at some point before invoking cleanup()) the responsibility to reset to zero, unless changes again.
Lines 38, 40, and 41 work the same way as lines 3, 6, and 7 of LL() to try to protect the current tag stored in , preventing from resetting after an ABA. If is zero then can return immediately (line 39). If changes from , then CL() no longer needs to reset , so it simply decrements its usage count, ending its protection of tag (line 45). Otherwise, next double-checks that the activity counter is still zero (line 42). This second check of ensures that any process which changes does so after ’s execution of line 42, while is protected. Lines 43 and 44 work similarly to lines 28 and 29 of SC(): attempts to CAS() from to zero, and if successful then decrements tag ’s usage count since is no longer used in . (Note that, in the case of a successfully reset tag, decrements twice, in lines 44 and 45: The first decrements ’s usage count associated with the initial lock in line 19 or line 27, whereas the second ends ’s protection of the tag.)
Read($i \in \{1,\ldots,m\}$)
46 return $L[i]$.Read().val
VL($i \in \{1,\ldots,m\}$)
47 if $d[i] = \bot$ then return False
48 if $L[i]$.Read().tag $\in \{d[i]$.tag, 0\} then return True
49 CL($i$)
50 return False
Read() and VL() Methods
The Read() and VL() methods are the same as in [9].
A Read() call simply returns the contents of .val, as it has no need to do anything with the tag field.
Conversely, a VL() call only checks .tag in line 48, linearizing at the point of the read. If VL() is called by a process with an outstanding LL() (which is the intended case, as it would otherwise return in line 47), then would have already protected the tag that it read earlier and stored in .tag. This protection prevents ABAs while has an outstanding LL(), and therefore if .tag = .tag then it also follows that did not change in between the linearization points of LL() and VL(). VL() also checks if .tag = 0 because of the same edge case discussed for SC() in Section 3.2.3. If .tag is a different nonzero value, then does not have an open link to , and so calls CL() in line 49 to also clear its outstanding LL().
Analysis
This section formally proves Theorem 1. Several proofs closely follow the format of those of [10], but with significant changes throughout due to adding the Write() operation and making the required changes to SC() and CL().
Lemma 3. When a process responds from a CL(), Write(), or SC() call, its value of is .
This lemma corresponds to Lemma 1 of [10], and its proof is mostly unchanged, except that it also applies to Write().
Proof. For CL(), if the calling process returns in line 34, then the lemma is satisfied by the if-condition in that line. Otherwise, sets to in line 36 and does not change it again (including in cleanup(), if called) until its response.
For Write(), if upon invocation, then the calling process calls CL() in line 15, which by the above ensures that by its response. The rest of the call does not change again, including in a possible call to cleanup().
For SC(), if the calling process returns in line 23, then the lemma is satisfied by the if-condition in that line. Otherwise, calls CL() in line 32, which by the above ensures that by its response, and then immediately returns.
Lemma 4. If for a process while does not have a pending method call on , then has an outstanding LL().
This lemma corresponds to Lemma 2 of [10], and its proof is mostly unchanged.
Proof. Only can set to a non- value. By Lemma 3, the , , and methods ensure by their respective responses. If a call returns False, then either in line 47, or it calls in line 49, so in both cases by the point it returns False. Thus, if while is idle, then has called and not subsequently called , , , or a call which returns False, so by Definition 2 has an outstanding .
Contributions to Counters
The following definition corresponds to Definition 3 of [10], but is more complicated because LL/SC objects can now contribute to elements of , with said contribution able to transfer between processes and LL/SC objects. Intuitively, a contribution by to represents ’s responsibility for eventually decrementing the value of . That responsibility is initially generated by ’s increment of (from a or a successful ). When a process installs a new tag to for some object , it transfers that responsibility to . When is subsequently replaced by a process, the responsibility transfers to the replacing process, which then performs the decrement of .
Definition 5 (Contribution). Given a point , a process , and element , contributes to ’s value, if is the number of minus operations that has executed on before .
For each element , processes increase their contributions by performing a or a successful operation on , and decrease their contribution to by performing a operation on . In addition, contributions to can also transfer between processes and LL/SC objects, without changing the total contribution to or the value of , as follows:
Suppose a process executes an operation in line 20 or a successful operation in line 28 or 30 at point . Then, ’s contribution to ’s value decrements by one and ’s contribution to ’s value increments by one at point .
Suppose a process reads from an operation in line 20, or executes a successful operation in line 28 or 43 at point . Then, ’s contribution to ’s value increments by one and ’s contribution to ’s value decrements by one at point .
Lemma 6. When a process invokes or responds from a method call, including the helper method ,
(a) if , then contributes zero to , and otherwise contributes one to , and
(b) the total contribution to by , for , equals the number of non- values in ’s dictionary which have as their tag.
At all points in the execution,
(c) the number of objects for which for is at most ,
(d) contributes either zero or one to each individual element of , and
(e) contributes a total value in to the elements of , with a non-negative contribution to each individual element.
This lemma corresponds to Lemma 4 of [10], but (e) is a per-process bound and includes a lower bound of zero, with a global lower bound proven later in Corollary 9.
Proof. Note that by Definition 5, ’s contributions to and , as well as its dictionary , do not change while is idle. Thus, if (a) through (e) hold when responds from a method call and becomes idle, then they also hold until the point when next invokes a method.
As such, we prove (a) and (b) for a process by induction over its method calls, including the helper method cleanup(), while proving that (c) through (e) hold at all points within each of ’s method calls.
Initially, contributes zero to elements of and and its dictionary is empty (all values are ), so (a) through (e) hold before ’s first method call.
Suppose that (a) through (e) hold for before the invocation of a given method: we will prove that (c) through (e) hold throughout the method call, and that (a) and (b) hold at the call’s response.
If the method call is Read(i), then (a) through (e) hold because Read() does not affect ’s contributions or its dictionary .
We next consider the CL(i) method. If the call returns immediately in line 34, then neither ’s contribution nor change, so (a) through (e) remain true. Otherwise, at invocation, so by (a), ’s contribution to is one at invocation. Since the cleanup(i) method is called as the last step, if it is called at all, it suffices to show that (a) and (b) hold immediately after the FAD() on in line 37, and (c) through (e) hold until just after that decrement. Since does not set any non- value in throughout the method call, (c) remains satisfied. Since resets to in line 36 and decrements in line 37, ’s contribution to becomes zero which satisfies (a) after the decrement. In particular, ’s contribution is either zero or one throughout the call, so (d) is satisfied throughout the call.
If at invocation, then does not make any change to in line 35, so (b) and (e) remain true throughout the call. Otherwise, is nonzero at invocation, so by (b) contributes at least one to at invocation. In this case, decrements in line 35, satisfying (b) again after line 36. In particular, since ’s total contribution to is non-negative at invocation by (e), its contribution to is positive at invocation by (b), and it only decrements , (e) is satisfied throughout the method call. Thus, both cases satisfy (b) and (e).
Next, consider the cleanup(i) helper method. Since it does not modify or , (a), (c), and (d) remain satisfied. If responds in line 45, then it increments and later decrements the value of for its local variable , in lines 40 and 45, which exactly counteract each other’s effect. If executes a successful CAS() in line 43, then (by Definition 5) it increments its contribution to for its local variable , and then decrements that contribution to when executes its next step in line 44. Since the method does not modify , and any contribution increments are followed by contribution decrements of the same element of , (b) holds at ’s response in line 45 or 39. From (e) and (c), ’s total contribution to elements of is at most when invoking cleanup(i). Since ’s contribution increases at most twice in cleanup(i), and since all decrements of contributions to elements of follow increments of that same element in the same method, (e) remains satisfied.
Since the VL() method does not change ’s contribution to or or its dictionary except via its internal CL() call, (a) through (e) hold for VL() by the above arguments for CL() and cleanup().
We next consider the Write(i,·) method, before the possible call to cleanup(i) in line 22. We have that (a), (c), and (d) remain true throughout the method call, since ’s dictionary and its contribution to do not change in the method. By (b) and (c) from the inductive hypothesis, contributes at most to elements of at invocation. Then, ’s contribution to increments by one at a successful CAS() in line 19, and decrements by one in line 20. If the value read from in line 20 is nonzero, then ’s contribution to increments by one in line 20 and decrements by one in line 21. In both cases, ’s contributions to elements of before line 22 changes back to what they were at invocation, satisfying (b) before line 22. Since ’s total contribution to does not increase by more than one relative to invocation throughout the method call, and all increments are then cancelled out for the same element of , (e) remains satisfied throughout the method call.
The arguments for the SC(i, ·) method are similar to those for Write(i, ·), but there are more cases to consider. Here, we need to consider steps, up to just before it calls CL(i) in line 32. Since the steps of SC() excluding CL() do not change the values in or ’s contributions to , it again follows that (a), (c), and (d) remain true throughout those steps.
If the SC(i, ·) call returns in line 23, then (b) and (e) also hold throughout the call since the call does not change or . Otherwise, at invocation, so we consider the lines up until line 32. Again by (b) and (c) from the inductive hypothesis, contributes a non-negative integer of at most to the elements of at SC(i, ·)’s invocation. Thus, when breaks out of its while-loop via a successful CAS(0, 1) in line 27, its contribution to increments by one, and its total contribution to is at most immediately after that line. By Definition 5, that contribution lasts until either a successful CAS() in line 28 or 30, or upon a FAD() in line 31.
If has a successful CAS() in line 28, and if , then ’s contribution to is decremented and its contribution to is incremented at that point, which does not change ’s total contribution to . Exactly in that case, executes the .FAD() in line 29, undoing the effect of incrementing its contribution to . By inspection of the code and Definition 5, ’s contribution to decrements by one in exactly either line 28, 30, or 31, bringing ’s total contribution to back to at most .
Since all increments of elements of by are then decremented for the same element in the method, its contributions immediately before line 32 are the same as at invocation, thus satisfying (b) before line 32. In particular, ’s contribution to increments by one and then decrements by one, with the decrement possibly happening simultaneously with an increment of the contribution to followed by a corresponding decrement. Therefore, because ’s total contributions to at invocation are in , and from (e) contributes a non-negative value to each element of at invocation, (e) remains satisfied throughout the call.
It remains to show (a) through (e) for an LL(i) call by . Since they each remain true after CL() calls by the above arguments, they each remain true by the time the LL(i) call reaches line 2.
Since, by Lemma 3, the CL(i) call in line 1 ensures that , it follows by (a) that ’s contribution to immediately before line 2 is zero, and hence its contribution immediately after the FAI() is one. In particular, at all points ’s contribution to is either zero or one, satisfying (d) throughout the call. After executing line 4, (a) becomes true again, and remains true until ’s possible invocation of CL(i) in line 13, then remains true at its response by the above arguments for CL(), and therefore (a) is true at any possible response from LL(i). (Note that line 11, if executed, only changes the value of from one non- value to another.) Recall from Section 2.4 that is required to have at most outstanding LL() operations to objects other than before invoking LL(i). Thus, by Lemma 4, there are at most objects such that for before the call’s invocation. Since after line 1, it follows that after executing line 4, there are at most non- values in , and so (c) remains true throughout the call. Since (b) holds immediately before executes line 2, and the number of non- values in is less than at that point, it follows that line 6 does not increase ’s contribution to past . By the inductive hypothesis and that CL() preserves (e), (e) holds from invocation until just before line 6 (or a response in line 5). It follows that ’s contribution to is at least 1 after the FAI() in line 6, and therefore remains non-negative after a possible FAD() in line 10. Therefore, ’s contribution to is in throughout the LL(i) call, with a non-negative contribution to each element which is more than enough to satisfy (e) throughout the call. Finally, we can verify that (b) holds at each relevant response point and the possible invocation of CL(i) in line 13, using that it holds immediately after line 1 with at that point. In line 5, and is untouched by ; in lines 8 and 13, and is incremented; and in line 12, and the increment of is reversed.
Lemma 7. The value of each element in equals the sum of the contributions from each process (i.e., no element overflows).
This lemma corresponds to part of Lemma 6 of [10], with the part referring to proven later in Lemma 12(a).
Proof. From Definition 5, each FAI() to an element of corresponds to an increment of the total contribution to that element. Similarly, each FAD() to an element of corresponds to a decrement of the total contribution to that element. Since no other operation affects the value of elements of , it suffices to show that the total contribution to each element remains in the range , thus never underflowing or overflowing the element’s value. From Lemma 6(d), process contributions to are either zero or one at all times. Therefore, each process contributes at most one to the value of each element of , and since objects do not contribute to elements of , it follows that the maximum contribution to any given element of is . It follows that the total contribution each element of is always in the range , implying the lemma.
Lemma 8. At point , if and only if contributes one to the value of . For all , contributes zero to the value of at point $t.
This is a new result, which we use to ensure correctness of the Write() method.
Proof. The only lines that can change ’s contribution to the value of an element of , by Definition 5, are lines 20, 28, 30, and 43. These are also the only lines that can change the value of . From Definition 5 and inspection of the code, the cases in which an object increments its contribution to for nonzero tag and the cases in which changes to nonzero tag are the same as each other: Both occur exactly in the event of an operation in line 20 or a successful operation in line 28 or 30. Similarly, from Definition 5 and inspection of the code, the cases in which an object decrements its contribution to for nonzero tag and the cases in which changes from nonzero tag are the same as each other: Both occur exactly in the event of an operation in line 20 that returns , or a successful operation in line 28 or 43. The above are not (yet) mutually exclusive: if a Swap() or successful CAS() on ‘changes’ from to , then by Definition 5 ’s contribution to tag both increments and decrements by one, and therefore does not change. (We later show in Lemma 14 that this cannot occur, but that result depends on this lemma.) Initially, for all , and no object contributes anything to any element of . From the above observations, it follows that increments its contribution to ’s value for nonzero exactly when changes to from a different tag. Similarly, decrements its contribution to ’s value exactly when changes from to different tag. The first part of the lemma thus follows by induction. Since only has one value, can therefore only contribute to at most one element of at a time, namely the element such that , proving the second part.
Corollary 9. At all points of the execution, the total contribution to any given element of or is non-negative, and it is positive if any process or object contributes a positive value to that element.
This statement is somewhat analogous to Lemma 5 of [10], but proven differently.
Proof. Since only processes contribute to , and by Lemma 6(d) they each contribute either zero or one to each element, it follows that the total contribution to is non-negative, and positive if any process contributes one. The statement for follows from the combination of Lemma 6(e) and Lemma 8.
Locking Tags
An important new concept in this writable LL/SC implementation is that of locking tags. The SC() and Write() methods attempt to lock a tag as defined below to ensure that they do not choose the same new tag as a concurrent SC() or Write() call, which could lead to ABAs as argued in Section 3.1.
Definition 10 (Locked tag). A process locks tag for when has a successful CAS(0, 1) on in either line 19 or 27, as part of an SC() or Write() call. The tag then becomes unlocked when the total contribution to it according to Definition 5 becomes zero.
Lemma 11. While , tag is locked for . When a Swap() or a successful CAS() next takes effect on , tag remains locked until the process that executes that Swap() or CAS() takes its next step.
Proof. Initially, all tag fields are set to zero. Thus, if at point , then there is a point at which a Swap() in line 20 or a successful CAS() in either line 28 or 30 is executed by some process , changing to . Let be the latest such point, so that throughout . There is a point at which executes a successful CAS() in line 19 or 27 on , changing it from zero to one, and by Definition 5 and Lemma 6(e) increasing ’s contribution to from zero to one. By Definition 10, locks tag at point . From Definition 5, ’s contribution to does not change from to , ’s contribution is transferred to at point , and ’s contribution does not change from to . From Corollary 9, there is a non-negative contribution to throughout . Therefore, from Definition 10, tag remains locked throughout .
Now suppose that point is the first point after at which a Swap() in line 20 or a successful CAS() in either line 28 or 43 takes effect on , and let be the process performing that step. throughout , ’s contribution transfers to at point (from Definition 5), and this transferred contribution remains until its next step, which is line 21, 29, or 44, at point . From Corollary 9, there is a positive contribution to throughout . The final part of the lemma then follows from Definition 10.
Lemma 12. At each point in the execution,
(a) the value of each element in equals the sum of the contributions from each process and LL/SC object,
(b) while a tag is locked, no process can lock it a second time, and
(c) each process contributes at most one to each element of , unless a contribution was transferred from an object to the process in either line 20, 28, or 43. In the latter case, the process can contribute at most two to that element until it next executes line 21, 29, or 44, respectively.
Statement (a) corresponds to part of Lemma 6 from [10], with the part referring to proven earlier in Lemma 7.
Proof. We prove the three parts as a combined invariant by induction over the execution. They each hold at the beginning of the execution, since no process or object contributes to and no tag is locked initially.
We first show (b), by showing that if a tag becomes locked at point , and (a) holds at all points prior to , then is not locked immediately before . From Definition 10, there is a nonzero total contribution to throughout the interval in which tag is locked. Since point is the point of a successful on , it follows that immediately before point . From (a), it follows that no process or object contributes to immediately before , and therefore that is not locked immediately before .
We next show that (c) holds at point , given that (a), (b), and (c) hold at all points prior to point . Suppose that a process increments its contribution to at point (otherwise (c) holds immediately by the inductive hypothesis). If this comes from a transfer from an object, i.e., in either line 20, 28, or 43, then by the inductive hypothesis for (c), contributes at most one per tag immediately before point . Therefore, contributes at most two per tag immediately after point . In all transferred cases, decrements the transferred tag in the next line (line 21, 29, or 44, respectively), from which (c) follows.
Thus, we next consider the cases in which directly increments at point , in either line 6, 19, 27, or 40: in all cases, we will show that contributes exactly one to immediately after point . For lines 19 and 27, since they are operations, (c) follows from the inductive hypothesis that (a) holds immediately before , and that a total contribution of zero to implies zero contribution from each process (from Corollary 9).
The remaining (and most complicated) cases are that executes line 6 of an call or line 40 of a cleanup(i) call at point , which we consider together. Suppose for the purpose of proving a contradiction that already contributes at least one to immediately before point . It follows that there is a point at which incremented its contribution to , without decrementing its contribution to in .
Observe that the increments of contribution which can happen in lines 19, 20, 28, and 40 are necessarily followed by a decrement of contribution in lines 20, 21, 29, and 45, respectively, in the same method call. Similarly, the increment of contribution in line 27 is necessarily followed by a decrement of contribution in exactly one of either line 28, 30, or 31. In all the above-considered cases, does not execute line 6 or 40. Therefore, the only increment of contribution which is not cancelled out before point is that in line 6. Moreover, that call must respond in line 8, otherwise 's contribution is decremented in either line 10 or line 35 from the call in line 13. So, there is a point at which increments in line 6 of an call, and that 's contribution to stays at one until just before point .
Since 's call responds in line 8, there is a point at which reads from in line 7. From Lemma 11, is locked at point for . We next establish that by contradiction: suppose instead that . Since ’s contribution to is exactly one throughout , and each method call involves only one element of , Lemma 6(b) implies that at ’s method invocations throughout the interval. In the case of executing line 6 at point , would call CL in line 1 before line 6, and decrement in line 35, contradicting that does not decrement throughout . In the case of executing line 40 at point , recall that calls cleanup from either Write or CL. If called from Write, previously calls line 15 and calls CL in that line, since the call occurs after the LL call which includes point , and therefore at method invocations. The CL call then decrements in line 36 as , which again contradicts that does not decrement throughout .
At point , reads from in line 3. Using Lemma 11 again, it follows that is locked for at point . But since contributes one to throughout , by Definition 10, is never unlocked for in that interval. Thus, at point , is locked for both and , which contradicts (b) before point $t, and finishes the inductive case for (c).
To conclude the proof, we show that (a) holds at point , given that (b) and (c) hold at point . From Definition 5, the total contribution to a given element of increases or decreases exactly when that element is incremented (including via CAS) or decremented. (In particular, transfers of contribution between processes and objects do not change the total contribution to any element of .) Since Corollary 9 establishes that contributions are non-negative, to prove (a) it suffices to show that the total contribution to a given element of does not exceed at point , and thus that the element never overflows.
From Lemma 11 and (b), a given tag has a total contribution of at most one from all LL/SC objects at point . If at point , no process previously received a transferred contribution to in either line 20, 28, or 43 without having taken its next step of decrementing , then by (c), each process contributes at most one to . Thus, in this case, the total contribution to is at most , which would imply (a).
To finish proving (a), we will show that, at point , there can be at most one process to which tag was transferred without the subsequent decrement, and that if such a process exists, then no object contributes to . Suppose then that at point , some process executes either line 20, 28, or 43, gets transferred the nonzero tag from , and does not execute its next line until after point . From Lemma 11, remains locked throughout .
Suppose for the purpose of proving a contradiction that (possibly ) contributes to at some point ; by Lemma 8, at this point. (If a second process is transferred tag at some point in that interval, then for some object immediately before the transfer, so that is also covered by this supposition.) Then there are points such that at point , some process locks tag in line 19 or 27, and at point , causes to become in line 20, 28, or 30. Since is locked for immediately before point , there is a point at which becomes locked for by some process . Since, from the code for Write() and SC(), a process performs either a single Swap() on an object or at most one successful CAS() to set a tag field after locking a tag, it follows that . Whichever point is later between and contradicts (b), because becomes locked at the earlier of the two points, and remains locked until at least point which is later than both.
In summary, each process other than one process with a transferred tag contributes at most one to , and there can be either one more contribution from an object, or one process with a transferred tag contributing two to . It follows that the total contribution to any element of is at most in all cases, thus obtaining (a) since the elements do not overflow. ◂
Corollary 13. While tag is locked by process for , only can cause to change to .
Proof. Suppose that changes to at point by process , while is locked by process . Since (by Definition 10) only nonzero tags can be locked, the possible lines which can be executed at point are lines 20, 28, and 30. In each case, there is a point at which breaks out of a loop, in line 19 or 27. From Definition 10, locks tag at point , and does not unlock until after point . From Lemma 12(b), , proving the corollary. ◀
Lemma 14. If at point some process executes line 20, or a successful CAS() in line 28 or 30, then changes from some tag to a new tag at point .
This lemma is analogous to Lemma 18 of [10], but its proof uses the new concept of locking tags.
Proof. Let be the process that executes line 20, or a successful CAS() in line 28 or 30 at point , and let be the value of immediately after that point. Since chooses in line 18 or 26 from the set , it follows that , so it remains to show that immediately before .
Let be the point at which breaks out of its loop in line 19 or 27. Since immediately before , it follows from Lemma 8 and Lemma 12(a) that at . From Definition 10, is locked by at point , and remains locked until it decrements its contribution to , which by Definition 5 occurs immediately after point (transferring its contribution to ). Since at point , it follows from Corollary 13 that throughout , which concludes the proof. ◀
Protecting Tags
Definition 15 (Protected and Strongly Protected Tags). A tag becomes protected for LL/SC object at point by a process if either
(a) reads zero from in line 3 or 7 at point , in which case , or
(b) reads from in line 7 or 41 at point , such that its local variable pair (read from in line 3 or 38 respectively) equals the value of at point .
If a tag becomes protected for during an LL() call, then it is also strongly protected for by . In that case, the protection and strong protection by process end when the calling process next invokes CL(). Otherwise, the tag becomes protected for during a cleanup() call, in which case it is not strongly protected by process , and the protection by ends when that call returns.
If a tag is protected or strongly protected by any process at point for , we also simply refer to it as protected or strongly protected for , without referring to the protecting process.
The only difference compared to Definition 9 of [10] is that protecting tags in the CL() method moves to the cleanup() helper method.
Lemma 16. If some tag is strongly protected for at point , then at point .
This lemma corresponds to Lemma 10 of [10], and its proof is nearly identical.
Proof. From Definition 15, a tag can only become strongly protected for by a process in an LL() call in line 3 or 7, and both lines happen after increments in line 2 and before its next invocation of CL(). Since only CL() can decrement (in line 37), it follows that ’s strong protection of for ends before it decrements . From Definition 5, contributes to throughout its strong protection of . The lemma then follows from Lemma 6(d) and Lemma 7.
Lemma 17. If a process has no pending method call on at point , then strongly protects tag for if and only if for 's dictionary at point .
This corresponds to Lemma 11 of [10], and the proof is essentially identical.
Proof. We first note that the only case in which can protect a tag for while not having a pending method call on , by Definition 15, is if it protected the tag as part of an call. In particular, this implies that also strongly protects the tag. Moreover, only can set to a non- value (in lines 4 and 11) and only can reset to (in line 36). An invocation of ends 's (strong) protection of any tag for by Definition 15, and, from Lemma 3, when responds. It therefore remains to show that an call strongly protects tag for by its response if and only if at that call's response.
To show this, we consider the five possible response points from an call by process . Suppose by induction that the lemma is true before the call begins (the base case holds since and processes protect no tags at ). If protects some tag for just before invocation of the call, then before invocation, and therefore invokes in line 1. Thus, after line 1, does not protect any tag for , and .
If responds in line 5 or 12, then reads zero from in line 3 or 7 respectively. By Definition 15(a), strongly protects tag zero for and sets to zero in line 4 or 11 respectively before it responds.
If responds in line 8, then re-reads its local variables from in line 7 after having set to in line 4 and not changing it afterwards. By Definition 15(b), strongly protects in line 7, at which point .
Otherwise, responds in line 14, in which case the call invoked in line 13 resets to and ends any protection of a tag by for .
Lemma 18. Suppose that a successful takes place on at point , such that immediately after . At point , some process executes line 28 or 30 of an call. Process strongly protects some tag for from the invocation of its call until at least point .
This is a slightly simpler version of Lemma 12 from [10]. Note that the lemma phrasing supposes that a operation specifically takes place at point , which rules out that a in line 20 takes place instead.
Proof. Since only lines 28 and 30 are operations which can change to a nonzero value, it follows that point is the point that some process executes one of the two lines. Since does not return in line 23, by Lemma 17, strongly protects for when it invokes . Moreover, since does not invoke in between invoking and its successful at point , by Definition 15 remains strongly protected for until at least point .
History Independence
Having established the useful properties of our implementation, we can now prove our results, starting with the QHI-preserving property. This result, proven in Theorem 21, is the same statement as Theorem 15 of [10], but with more work needed to prove it.
Lemma 19. If no process has a pending method call on and no process strongly protects a tag for at point , then at point . If no process has a pending method call on any object and no process strongly protects any tag at point , then for all .
Proof. Suppose that no process has a pending method call on and no process strongly protects any tag for at point . If for some process, then for some tag . From Lemma 17, would strongly protect at point ; thus, for all processes at point . Lemma 6(a) and Lemma 7 then imply that at point . If no process has any pending method call or strongly protects any tag at point , then Lemma 6(b) and Lemma 12(a) imply that for all .
Lemma 20. If at point no process has a pending method call on , except possibly a pending next step of line 44 or 45, and no process strongly protects a tag for , then at point .
This lemma corresponds to Lemma 14 of [10], but with more cases to consider.
Proof. The lemma is true for , since is initialized to zero for each . The method cannot be pending and does not affect which tags the calling process protects or the value of , so we need not consider it for this lemma. Similarly, by Lemma 17, we have that method calls which respond in either line 23, 34, or 47 do not affect which tags the calling process strongly protects or the value of . Method calls on objects also do not affect whether the calling process strongly protects a tag for of the value of . Note that all the method calls mentioned so far are either not for , or consist of at most one shared memory step before returning. Therefore, none of them change whether a process has a pending method call on . We can therefore assume without loss of generality that point is either the response point of a method not covered by this paragraph, or (immediately after) an execution of line 43.
By inspection of the code and by Definition 15 and Lemma 17, the remaining method calls for which the calling process responds without strongly protecting a tag for at the response point are exactly
(a) an call that responds in line 14,
(b) an call that responds in line 33,
(c) a call that responds after line 34,
(d) a call that responds in line 50, and
(e) a call.
The cases of responding in either line 14, 33, or 50 all immediately follow a call. As such, we can further assume that point is either the response point or an execution of line 43 from a or a call .
By Lemma 19, at point if it is a response point. Since lines 44 and 45 do not affect , and in all cases there are no shared memory operations after line 45 until the calling process becomes idle, it also follows that if is an execution of line 43. Since call does not respond in line 34, either it decrements in line 37, or it is a call. Therefore, there is a point before at which either is decremented to zero, or line 20 of a call takes place. (Note from the code that neither can take place at point itself.) Let be the last such point before point . Since only line 37 decrements , it follows that either some call (possibly ) decrements to zero at point , or a call executes line 20 at point . Let be the process executing call . By definition of , we also have that no Write(i, ·) call executes line 20 in the interval , and throughout the interval. If is a CL(i) call, then sees a 1 from the FAD() in line 37, and then invokes cleanup(i). Otherwise, is a Write(i, ·) call, and so it reads when it executes line 22 in , and therefore also invokes cleanup(i). Since no process has a pending method call on at point other than possibly lines 44 or 45, ’s call has executed line 43 or responded by point .
Since throughout the interval , by Lemma 16, we have that no tag is strongly protected for throughout . Therefore, from Lemma 18, no successful CAS() takes place on in that sets to a nonzero value. Since the only other line which can change to a nonzero value is line 20, and this line is not executed in , it follows that does not change to a nonzero value in that interval. In particular, if changes at all in the interval, it only does so from a successful CAS() in line 43, which changes to zero without changing . It thus suffices to show that at some point during ’s cleanup(i) call.
If responds from its cleanup(i) call in line 39, or if the if-condition in line 41 is False, then changes at some point in , and therefore changes to zero at that point, proving the lemma. Otherwise, we have that reads zero from in line 42, and therefore executes the CAS() in line 43. If the CAS() succeeds, then immediately after it, and therefore by point , proving the lemma. Otherwise, changes at some point after and before the CAS() attempt, and so we again have that at that point. ◀
Our first main theorem establishes that in a settled state (defined in § 1), all shared memory apart from LL/SC values stored in val fields are set to their default values of zero, implying that our implementation preserves quiescent history independence.
Theorem 21. If every process is idle and has no outstanding LL() operation on any LL/SC object at point , then all values of , , and all tag fields of are zero at point .
This theorem corresponds to Theorem 15 of [10].
Proof. From Lemma 4, all values of are for every process at point . From Lemma 17, no process strongly protects any tag at point . The theorem then follows from Lemmas 19 and 20. ◀
Expected Step Complexity
The core idea to prove expected step complexity is the same as in [10], but the main additional difficulty compared to that paper is in keeping track of contributions in § 4.1 and Lemma 22.
Lemma 22. At all points in the execution, the total contribution to all elements of is at most .
Proof. From Lemma 6(e), each process contributes at most in total to the elements of at any given time.
From Lemmas 8 and 20, for each LL/SC object which contributes one to some element of , there exists a process that either
has a pending method call on , other than a pending next step of line 44 or 45, or
strongly protects some tag for .
In the case of a process without a pending method call on which strongly protects some tag for , by Lemma 17 for that process, and by Lemma 4 the process has an outstanding LL(i). As required in 2.4, each process has at most outstanding LL() operations on objects for which it does not have a pending method call. Thus, each process can be associated with at most contributions to from LL/SC objects.
However, from Lemma 4, Definition 5, Lemma 6(b), and inspection of the code, the only situation in which a process can contribute exactly to the elements of is if
the process has outstanding
LL(i)operations, andits last step was a successful
CAS()in line 43, making its pending next step of line 44.
This scenario is mutually exclusive with that of an LL/SC object contributing to an element of due to that same process having a pending method call on , since it cannot have line 44 as its pending next step. As such, each process can be associated with at most total contributions to . Thus, the total contribution to is at most .
Theorem 23 (Expected Step Complexity). Each method other than Write() and SC() has a constant bound on its number of steps. The expected step complexity of the Write() and SC() methods is constant under a weak adaptive adversary.
This theorem corresponds to Theorem 7 of [10].
Proof. The first part is immediate from the fact that the only loops in the implementation are lines 17 to 19 of the Write() method and lines 25 to 27 of the SC() method.
For the second part, recall that under the weak adaptive adversary, a random choice by process is immediately followed by its next shared memory step. Thus, when chooses a random tag in line 18 or 26, it then immediately attempts a CAS() on in line 19 or 27, respectively, without any other process taking a step in between the two respective lines. In particular, the value of does not change in between the two lines. Therefore, ’s CAS() on from zero to one in line 19 or 27 succeeds if and only if when executes line 18 or 26, respectively. Thus, breaks out of its loop as soon as it chooses a tag such that when executes line 18 or 26, in which case it sets to one upon exiting the loop. Since this random choice is uniform over and independent, it suffices to show that, at any given time, at least a constant fraction of the indices in have a value of zero.
From Lemma 22, the total contribution to all elements of is at most , and from Corollary 9, all contributions are non-negative. Thus, at any given time, at least of ’s elements have zero contribution and hence, by Lemma 12(a), a value of zero, which completes the proof.
Linearizability
We conclude the analysis by proving in Theorem 29 that the algorithm is a linearizable implementation of the sequential specification from Section 2.3. There are more cases to consider compared to [10] due to the interaction between the Write() and SC() methods, but the new concept of locked tags makes some arguments a little simpler.
Lemma 24. If tag is protected for some object at point , then at point .
This corresponds to Lemma 16 of [10], with a slightly modified proof.
Proof. Suppose that process protects tag for some LL/SC object at point . Observe from Definition 15(b) that when a nonzero tag is protected in line 7 or 41, the process protecting it has incremented (in line 6 or 40 respectively) and not yet decremented . From Definition 5, therefore contributes a nonzero value to at point .
In the case of line 7, by Definition 15(b), matches ’s variable pair at point (so ); therefore, returns in line 8. If decrements its contribution by transferring it to an LL/SC object in either line 20, 28, or 30, then that decrement cancels out an increment in either line 19 or 27 of the same method call. Also, if decrements its contribution in either line 21, 29, or 44, then a contribution from an LL/SC object would have been previously transferred to in either line 20, 28, or 43. Thus, ’s contribution to does not decrement to zero until at least the next point after at which it decrements the value of within a CL call, in which case ceases to be protected for at that call’s invocation, or in line 10 of a subsequent invocation of LL. However, since only CL can reset to (in line 36), if invokes LL after point without invoking CL in between, then it invokes CL in line 1. This makes no longer protected for before decrements in line 10.
In the case of line 41, decrements in line 45, and possibly also in line 44. As mentioned earlier, if decrements in line 44, then it also increments its contribution to via a transfer from in line 43. Hence, ’s contribution can only decrement to zero in line 45, at which point ’s protection of ends.
Therefore, does not decrement its contribution to after point until after is no longer protected for . The lemma then follows from Lemma 6(e) and Lemma 12(a). ◀
Lemma 25 (Protection Invariant). Suppose that tag is protected for at point .
(a) does not change from a value different from to at point , and
(b) if is strongly protected for at point , then also does not change from a value different from to zero at point .
This lemma corresponds to Lemma 17 of [10], but the proof of (a) uses a different technique, using the new concept of locked tags.
Proof. We prove this lemma by contradiction. Suppose that the invariant is not true, and let be the first point in an execution at which it fails. Thus, at point , there exists a tag that is protected for , and changes from a tag to , or to zero if is strongly protected for .
Suppose first that (b) fails at point , and therefore that is strongly protected for at point , but that changes from some tag to zero at that point. Only line 43 can change to zero, since the only other lines which can change , namely lines 20, 28, and 30, choose a tag that is nonzero (from lines 18 and 26). Thus, there is a process which executes a successful CAS() in line 43 at point , changing from (’s local value of ) to zero. The if conditions that checks in lines 41 and 42 immediately before its CAS() at point both return true, since executes line 43. Therefore, there exist points , such that at point , and at point .
From Definition 15(b), becomes protected for at point , and it remains protected until executes line 45, which is after point . From Lemma 16, is not strongly protected for at point . Since by assumption is strongly protected for at point , becomes strongly protected for at some point . By Definition 15, at point . Since just before point , there is a point at which changes from some value different from (possibly ) to . But since is protected for throughout (recall that ), point violates (a), contradicting that is the first point at which the invariant fails.
It remains to derive a contradiction for the case where (a) fails at point , and therefore that changes from some tag to at point , while is protected for . Note that if , then it cannot become protected in line 41, as the cleanup() method would exit in line 39. Thus, if is protected then it is protected during an LL() call, and therefore it is also strongly protected, so the contradiction follows from that just derived for (b). We can therefore assume without loss of generality that .
Since the only lines that can change to a nonzero value are lines 20, 28, and 30, there is a point at which increments from zero to one, in line 19 or 27. By Definition 10, is locked by throughout the interval . Since immediately before point , by Lemma 24 we have that is not yet protected immediately before . Since, by Definition 15, lines 19 and 27 do not cause a tag to become protected, is also not protected at point , and so becomes protected at some point . By Definition 15, at point . Since immediately before , by Lemma 8 and Lemma 12(a) we also have that at point (recall that does not change at point ). Therefore, there is a point at which changes from some value different from to . The process taking the step at point is not , since does not change the value of in between points and . Since is locked by at point , this violates Corollary 13, which is a contradiction.
Definition 26 (Function ). We define a function from method calls in an execution to points in time, and later (in Theorem 29) prove that they are correct linearization points for the implementation.
If is an LL() call, then depends on which line the method responds from. If it responds in line 5 or 14, then occurs at line 3. If it responds in line 8 or 12, then occurs at line 7.
If is a Read() call, then occurs at line 46 (its only step).
If is a VL() call, then occurs at its invocation if it returns in line 47, and otherwise occurs at line 48.
If is a Write() call, then occurs at line 20.
If is an SC() call, then occurs at its invocation if it returns in line 23, and otherwise is the point of the last CAS() operation on . That is, if the CAS() in line 28 succeeds, then occurs at line 28, and otherwise occurs at line 30.
If is a CL() call, then occurs at its invocation.
For an execution with pending method calls, is undefined for pending LL() calls, and for other method calls for which the line corresponding to has not yet been executed.
The only new addition relative to Definition 19 from [10] is the Write() method, for which maps to the intuitive point of line 20.
Lemma 27. Suppose that is either an SC(i,u) or VL(i) call by process . The call returns True, and changes to at point , in the case of SC(i,u), if and only if
(a) some tag becomes strongly protected for by at some point , and remains strongly protected by throughout ,
(b) no Write(i,·) call executes the Swap() operation in line 20 in the interval ,
(c) no SC(i,·) call has a successful CAS() in line 28 or 30 in the interval ,
This lemma corresponds to Lemma 20 of [10], but here we have the new condition (b). The proof is mostly unchanged from that of [10].
Proof. We first prove the forward direction, so we first assume that returns True. Since returns True, it responds in either line 48 or 33. Since in particular it does not return in line 47 or 23, it means that when invokes . By Lemma 17, is strongly protected at ’s invocation, starting from some previous point , and by Definition 15 it remains protected until after . Thus, (a) is satisfied for some point .
Let be the tag that strongly protects at point , i.e., its value of in call . Suppose for the purpose of proving a contradiction that either (b) or (c) is false, so either line 20 or a successful CAS() in either line 28 or 30 takes place in , and let be the first such point. Note that the only other operation which can change the value of happens in line 43, which also sets to zero. Since, by Definition 15, at point , it follows that is either or zero immediately before point . By Lemma 14, changes to a different and nonzero value at point , and by Lemma 25, does not change to at point since is protected at that point. Thus, changes to some nonzero tag distinct from at point . Applying Lemma 25 to each change to in (if any), we obtain that can only change to other nonzero values distinct from throughout the interval. But, since we assume that returns True, and occurs at either line 28, 30, or 48, it follows from the code that immediately before , which is a contradiction. Thus, (c) and (b) follow, finishing the proof for the forward direction.
It remains to show the reverse direction, so we assume that (a), (c), and (b) each hold for . Like the forward case, let be the tag that strongly protects throughout , and we obtain from Definition 15 that at point . From Lemma 17, ’s value of is at ’s invocation, and in particular does not return in line 47 or 23. Since no step which can change to a nonzero value (i.e., line 20 or a successful CAS() in either line 28 or 30) takes place throughout , it follows that immediately before point . If is a VL(i) call, then the call returns True because is ’s value of . If is an SC(i, ·) call and its CAS() in line 28 succeeds, then the call returns True. Otherwise, the CAS() in line 28 fails, so performs a second CAS() in line 30, and is the point of that second CAS(). Since the only possible transition of ’s value in is from to zero, it follows that when executes line 28, and therefore remains at zero immediately before , making the second CAS() successful.
Lemma 28. Suppose that is an LL(i) call by process , such that and that the call responds at point . If some tag becomes strongly protected for by during the call, then it becomes strongly protected at point . Otherwise, some process executes a call which is either a Write(i, ·) call or an SC(i, ·) call with a successful CAS() at point , such that .
This corresponds to Lemma 21 of [10] with the only difference that an overlapping Write() operation can also cause an LL() call to not strongly protect a tag.
Proof. Combining Definitions 15 and 26, an LL() call that responds in line 5, 8, or 12 causes a tag to become strongly protected at , and an LL() call that responds in line 14 does not strongly protect any tag, proving the first claim. If responds in line 14, then ’s local variable and . In particular, at point , executes line 7, in which it reads from . Thus, there is some point at which first changes to a value not in . The only lines that can change to a nonzero value are a Swap() in line 20 or a successful CAS() in line 28 or 30, and by Definition 26 this operation is the linearization point of a Write(i, ·) or SC(i, ·) call. Hence, for some Write(i, ·) call or SC(i, ·) call with a successful CAS() on . Moreover, since and overlap, it follows that ’s calling process .
Theorem 29 (Linearizability). The LL/SC implementation is linearizable according to the sequential specification, with as the linearization point for each call .
This corresponds to Theorem 22 of [10], and the proof is mostly unchanged.
Proof. Consider an execution of writable LL/SC objects using this implementation. For each pending call in the execution such that is undefined according to Definition 26, we remove from the linearization. For each CL() call invoked internally from an LL(), SC() or VL() call, we also remove it from the linearization. We construct the linearization from the remaining calls, sorting them by . (Recall that cleanup() is a helper method, and so is not directly called in an execution. As such, it is not part of the linearization.)
We prove that this linearization is correct, by induction over calls sorted by . Specifically, we prove that each call returns a valid response and correctly affects the interpreted abstract state of the system. We inductively show that the interpreted value of LL/SC object is before and after each linearization point. This is true initially since is initialized to , the application-dependent initial value for . Recall from the sequential specification (§ 2.3) that the context bit of equals 1 (i.e., has an open link to ) immediately before a given method call of a sequential execution if and only if
an
LL(i)operation is called by process before call in the sequential execution,no
Write(i, ·)or successfulSC(i, ·)call (i.e., a call returningTrue) by any process takes place in between and , andno
CL(i)call by takes place in between and $c.
It also follows from the sequential specification that the context bit only directly affects the return value of SC(i, ·) and VL(i) calls. As such, to prove correct behaviour of context bits, it suffices to show that SC(i, ·) and VL(i) calls return True if and only if the relevant context bit should be 1 immediately before the respective call in the linearization.
If is a Read(i) or LL(i) call, then its correctness follows from the fact that the call returns at .
If is a Write(i, u) call, then its correctness follows from the fact that immediately after , since takes place at the call’s execution of Write, which unconditionally writes into . If an SC(i, u) call returns True, then immediately after , since by Definition 26 has a successful CAS() changing to at point . From the code and Definition 26, changes at point only if there is a call with , such that is either a Write(i, u) call, or an SC(i, u) call which returns True. In both cases, changes to at point . Therefore, if is an SC(i, u) or VL(i) call by process , we only need to show that it returns True if and only if the interpreted context bit , based on the three conditions listed earlier.
Suppose that an SC(i, u) or VL(i) call by process does return True, and we will show that before according to the three conditions. By Lemma 27(a), there is a point at which some tag becomes strongly protected for by ’s calling process , and it remains strongly protected until at least . By Definition 15, only an LL(i) call by can cause to strongly protect , and by Lemma 28, becomes strongly protected at point .
Since a CL(i) call by ends its strong protection of any tag for , and remains strongly protected from until at least , it follows that does not call CL(i) in between and . By Lemma 27(c) and (b), no SC(i, ·) call has a successful CAS() on in the interval , and no execution of line 20 takes place in that interval. Since an SC(i, ·) call with a successful CAS() operation returns True and has at the point of that CAS(), it follows that there is no such call with . Similarly, since a Write(i, ·) call has at its execution of line 20, there is no such call with . Therefore, the three conditions are satisfied and the interpreted context bit immediately before , as required.
Now suppose that the interpreted context bit immediately before call for an SC(i, ) or VL(i) call by process . Then, by the three conditions, has an LL(i) call with , such that does not directly call CL(i) in between and . There is also no successful CAS() from an SC(i, ·) call in line 28 or 30 such that , and no Swap() from a Write(i, ·) call in line 20 such that .
Suppose without loss of generality that is the last LL(i) call by before (if the three conditions hold for an earlier LL(i) call, then they also hold for ). From Lemma 28, some tag becomes strongly protected by at point (since responds from before it invokes ). In order to use Lemma 27, we need to show that this strong protection lasts until at least , and in particular that does not indirectly call CL(i) in between and . (Recall that indirect calls of CL() are removed from the linearization). The possible indirect calls of CL(i) are in lines 1, 13, 32, and 49, so we will show that does not execute any of these lines in between and by deriving contradictions for each case.
For line 1, since the line occurs before any possible line mapped to by for LL(), it would have to be part of an LL(i) call after , which contradicts that is the last LL(i) call by before . For line 13, by the above arguments it should be part of call , but by Definition 15 and inspection of the code, no tag becomes strongly protected during , which contradicts that some tag does become strongly protected at point . Line 32 would be part of an SC(i, ·) call, so we will show that does not make any such call in between and . If such a call were to return True, this contradicts the assumption there is no SC(i, ·) call which returns True in the linearization in between calls and . If such a call were to return False, then by the inductive hypothesis there is another SC(i, ·) call which returns True with , and this also contradicts our assumption. This last argument also applies if executes line 49 in between and , since that line is only executed in a VL(i) call which returns False.
We therefore have that a tag becomes strongly protected by for at point and remains so until at least point . Since no successful CAS() from an SC(i, ·) call and no Swap() from a Write(i, ·) call takes place in between and , from Lemma 27, does return True.
Since CL() only affects , which itself only becomes visible via SC() and VL() calls which we have already covered, the proof is complete.
Theorems 21, 23, and 29 together imply Theorem 1.
Conclusion
We have shown how to support an unconditional and randomized wait-free Write() operation to a QHI-preserving LL/SC implementation [10], using base objects that support swap, compare-and-swap, and fetch-and-increment/decrement, with the same asymptotic space and expected complexity. The changes require significant modifications to the technical analysis in order to prove that the results still hold with this larger set of supported operations. Our result paves the way for designing more algorithms in the new field of history-independent concurrency. A natural open problem is to implement more primitive operations in software that preserve history independence.
References
- [1]Umut A. Acar, Guy E. Blelloch, Robert Harper, Jorge L. Vittes, and Shan Leung Maverick Woo. Dynamizing static algorithms, with applications to dynamic trees and history independence. In Proceedings of the 15th ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 531–540, 2004. URL: http://dl.acm.org/citation.cfm?id=982792.982871.
- [2]Zahra Aghazadeh, Wojciech Golab, and Philipp Woelfel. Making objects writable. In Proceedings of the 33rd ACM Symposium on Principles of Distributed Computing (PODC), PODC ’14, pages 385–395, 2014. doi:10.1145/2611462.2611483.
- [3]Zahra Aghazadeh and Philipp Woelfel. Upper bounds for boundless tagging with bounded objects. In Proceedings of the 30th International Symposium on Distributed Computing (DISC), pages 442–457, 2016. doi:10.1007/978-3-662-53426-7_32.
- [4]James H. Anderson and Mark Moir. Universal constructions for large objects. In Proceedings of the 9th International Workshop on Distributed Algorithms (WDAG), volume 972, pages 168–182, 1995. doi:10.1007/BFb0022146.DOI
- [5]James H. Anderson and Mark Moir. Universal constructions for multi-object operations. In Proceedings of the 14th ACM Symposium on Principles of Distributed Computing (PODC), pages 184–193, 1995. doi:10.1145/224964.224985.
- [6]Hagit Attiya, Michael A. Bender, Martín Farach-Colton, Rotem Oshman, and Noa Schiller. History-independent concurrent objects. In Proceedings of the 43rd ACM Symposium on Principles of Distributed Computing (PODC), pages 14–24, 2024. doi:10.1145/3662158.3662814.DOI
- [7]Hagit Attiya, Michael A. Bender, Martín Farach-Colton, Rotem Oshman, and Noa Schiller. History-independent concurrent hash tables. In Proceedings of the 57th Annual ACM Symposium on Theory of Computing (STOC), pages 1283–1294, 2025. doi:10.1145/3717823.3718283.DOI
- [8]Naama Ben-David, Guy E. Blelloch, Michal Friedman, and Yuanhao Wei. Delay-free concurrency on faulty persistent memory. In Proceedings of the 31st ACM Symposium on Parallelism in Algorithms and Architectures (SPAA), pages 253–264, 2019. doi:10.1145/3323165.3323187.
- [9]Dante Bencivenga, Homa Habashi, and Philipp Woelfel. Efficient randomized LL/SC that preserves history independence. In Proceedings of the 40th International Symposium on Distributed Computing (DISC), volume 397 of LIPIcs, pages 12:1–12:24, 2026. doi:10.4230/LIPIcs.DISC.2026.12.DOI
- [10]Dante Bencivenga, Homa Habashi, and Philipp Woelfel. Efficient randomized LL/SC that preserves history independence. arXiv preprint, 2026. arXiv:2608.12946.DOI
- [11]Michael A. Bender, Jon Berry, Rob Johnson, Thomas M. Kroeger, Samuel McCauley, Cynthia A. Phillips, Bertrand Simon, Shikha Singh, and David Zage. Anti-persistence on persistent storage: History-independent sparse tables and dictionaries. In Proceedings of the 35th ACM SIGACT-SIGMOD Symposium on Principles of Database Systems, pages 289–302, 2016. doi:10.1145/2902251.2902276.
- [12]Guy E. Blelloch and Daniel Golovin. Strongly history-independent hashing with applications. In Proceedings of the 48th Annual IEEE Symposium on Foundations of Computer Science (FOCS), pages 272–282, 2007. doi:10.1109/FOCS.2007.36.DOI
- [13]Guy E. Blelloch and Yuanhao Wei. LL/SC and atomic copy: Constant time, space efficient implementations using only pointer-width CAS. In Proceedings of the 34th International Symposium on Distributed Computing (DISC), pages 5:1–5:17, 2020. doi:10.4230/LIPIcs.DISC.2020.5.DOI
- [14]Niv Buchbinder and Erez Petrank. Lower and upper bounds on obtaining history independence. Information and Computation, 204(2):291–337, 2006. doi:10.1016/J.IC.2005.11.001.DOI
- [15]Simon Doherty, Maurice Herlihy, Victor Luchangco, and Mark Moir. Bringing practical lock-free synchronization to 64-bit applications. In Proceedings of the 23rd ACM Symposium on Principles of Distributed Computing (PODC), pages 31–39, 2004. doi:10.1145/1011767.1011773.DOI
- [16]Wojciech Golab, Lisa Higham, and Philipp Woelfel. Linearizable implementations do not suffice for randomized distributed computation. In Proceedings of the 43rd Annual ACM Symposium on Theory of Computing (STOC), pages 373–382, 2011. doi:10.1145/1993636.1993687.DOI
- [17]Daniel Golovin. B-treaps: A uniquely represented alternative to B-trees. In Proceedings of the 36th International Colloquium on Automata, Languages, and Programming (ICALP), pages 487–499, 2009. doi:10.1007/978-3-642-02927-1_41.DOI
- [18]Daniel Golovin. The B-skip-list: A simpler uniquely represented alternative to B-trees. arXiv preprint, 2010. arXiv:1005.0662.arxiv.org/abs/1005.0662
- [19]Jason D. Hartline, Edwin S. Hong, Alexander E. Mohr, William R. Pentney, and Emily Rocke. Characterizing history independent data structures. In Proceedings of the 13th Annual International Symposium on Algorithms and Computation (ISAAC), pages 229–240, 2002. doi:10.1007/3-540-36167-2_21.
- [20]Jason D. Hartline, Edwin S. Hong, Alexander E. Mohr, William R. Pentney, and Emily C. Rocke. Characterizing history independent data structures. Algorithmica, 42(1):57–74, 2005. doi:10.1007/S00453-004-1140-Z.DOI
- [21]Maurice Herlihy. Wait-free synchronization. ACM Transactions on Programming Languages and Systems, 13(1):124–149, January 1991. doi:10.1145/114005.102808.DOI
- [22]Maurice P. Herlihy and Jeannette M. Wing. Linearizability: A correctness condition for concurrent objects. ACM Transactions on Programming Languages and Systems, 12(3):463–492, 1990. doi:10.1145/78969.78972.DOI
- [23]Amos Israeli and Lihu Rappoport. Disjoint-access-parallel implementations of strong shared memory primitives. In Proceedings of the 13th ACM Symposium on Principles of Distributed Computing (PODC), pages 151–160, 1994. doi:10.1145/197917.198079.DOI
- [24]Prasad Jayanti. A complete and constant time wait-free implementation of CAS from LL/SC and vice versa. In Proceedings of the 12th International Symposium on Distributed Computing (DISC), volume 1499 of Lecture Notes in Computer Science, pages 216–230, 1998. doi:10.1007/BFb0056485.DOI
- [25]Prasad Jayanti, Siddhartha Jayanti, and Sucharita Jayanti. Durable algorithms for writable LL/SC and CAS with dynamic joining. In Proceedings of the 27th International Symposium on Distributed Computing (DISC), volume 281 of LIPIcs, pages 25:1–25:20, 2023. doi:10.4230/LIPIcs.DISC.2023.25.DOI
- [26]Prasad Jayanti and Srdjan Petrovic. Efficient and practical constructions of LL/SC variables. In Proceedings of the 22nd ACM Symposium on Principles of Distributed Computing (PODC), pages 285–294, 2003. doi:10.1145/872035.872078.DOI
- [27]Prasad Jayanti and Srdjan Petrovic. Efficient wait-free implementation of multiword LL/SC variables. In Proceedings of the 25th International Conference on Distributed Computing Systems (ICDCS), pages 59–68, 2005. doi:10.1109/ICDCS.2005.29.DOI
- [28]Prasad Jayanti and Srdjan Petrovic. Efficiently implementing a large number of LL/SC objects. In Proceedings of 9th International Conference On Principles Of Distributed Systems (OPODIS), pages 17–31, 2005. doi:10.1007/11795490_4.DOI
- [29]Prasad Jayanti and Srdjan Petrovic. Efficiently implementing LL/SC objects shared by an unknown number of processes. In International Workshop on Distributed Computing (IWDC 2005), pages 45–56, 2005. doi:10.1007/11603771_5.DOI
- [30]Chaitanya Koparkar. A primer on pointer tagging. XRDS: Crossroads, The ACM Magazine for Students, 29(1):66–68, 2022. doi:10.1145/3558200.DOI
- [31]Linux man-pages project. proc_sys_kernel(5): Control a Range of Kernel Parameters. February 2026. Version 6.19, accessed November 22, 2026. URL: https://man7.org/linux/man-pages/man5/proc_sys_kernel.5.html.
- [32]Victor Luchangco, Mark Moir, and Nir Shavit. Nonblocking k-compare-single-swap. In Proceedings of the 25th ACM Symposium on Parallelism in Algorithms and Architectures (SPAA), pages 314–323, 2003. doi:10.1145/777412.777468.DOI
- [33]Daniele Micianico. Oblivious data structures: applications to cryptography. In Proceedings of the 29th Annual ACM Symposium on Theory of Computing (STOC), pages 456–464, 1997. doi:10.1145/258533.258638.
- [34]Maged M. Michael. Practical lock-free and wait-free LL/SC/VL implementations using 64-bit CAS. In Proceedings of the 18th International Symposium on Distributed Computing (DISC), pages 144–158, 2004. doi:10.1007/978-3-540-30186-8_11.DOI
- [35]Mark Moir. Practical implementations of non-blocking synchronization primitives. In Proceedings of the 16th ACM Symposium on Principles of Distributed Computing (PODC), pages 219–228, 1997. doi:10.1145/259380.259442.DOI
- [36]Fatemeh Naderi-Sem iromi and Philipp Woelfel. Strongly linearizable LL/SC from CAS. In Proceedings of the 43rd ACM Symposium on Principles of Distributed Computing (PODC), pages 443–453, 2024. doi:10.1145/3665288.3662800.
- [37]Moni Naor, Gil Segev, and Udi Wieder. History-independent cuckoo hashing. In Proceedings of the 35th International Colloquium on Automata, Languages, and Programming (ICALP), pages 631–642, 2008. doi:10.1007/978-3-540-70583-3_51.DOI
- [38]Moni Naor and Vanessa Teague. Anti-persistence: history independent data structures. In Proceedings of the 33rd Annual ACM Symposium on Theory of Computing (STOC), pages 492–501, 2001. doi:10.1145/380752.380844.DOI
- [39]Julian Shun and Guy E. Blelloch. Phase-concurrent hash tables for determinism. In Proceedings of the 26th ACM Symposium on Parallelism in Algorithms and Architectures (SPAA), pages 96–107, 2014. doi:10.1145/2612669.2612687.DOI