https://github.com/mxinden/elimination-backoff-stack
Lock-free elimination back-off stack
https://github.com/mxinden/elimination-backoff-stack
concurrent-data-structure lock-free parallel rust stack
Last synced: 6 months ago
JSON representation
Lock-free elimination back-off stack
- Host: GitHub
- URL: https://github.com/mxinden/elimination-backoff-stack
- Owner: mxinden
- Created: 2020-03-15T14:46:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-06T06:36:05.000Z (over 3 years ago)
- Last Synced: 2025-03-25T03:24:57.869Z (6 months ago)
- Topics: concurrent-data-structure, lock-free, parallel, rust, stack
- Language: Rust
- Homepage:
- Size: 110 KB
- Stars: 12
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**Work in progress**
Before you consider using this ask yourself the following questions:
- *Is my workload running on a machine > 8 cores?*
If not you likely won't see enough contention that an elimination back-off
stack outperforms a classic Treiber stack or even an `Arc>>`.- *Do I trust the author's use of atomics?*
If yes, take a look at all `grep -r -E "compare_and_set"` anyways.
- *Do I need a single coordination point through a stack to solve my problem?*
Think about how you could solve your problem in a parallel fashion requiring
less coordination.# Lock-free elimination back-off stack
A normal lock-free Treiber stack [1] linearizes concurrent access through a
single atomic `head` pointer on which `push` and `pop` operations loop trying to
compare-and-swap it. Usually one uses exponential backoff to circumvent
contention. This results in a single sequential bottleneck and a lot of cache
coherence traffic.A [lock-free elimination back-off
stack](https://people.csail.mit.edu/shanir/publications/Lock_Free.pdf) wraps
such a lock-free Treiber stack, but instead of simply exponentially backing off
on compare-and-swap failures, it uses something called an `EliminationArray`.
Each slot within such an `EliminationArray` enables a thread executing a `push`
operation to hand its item over to a thread executing a `pop` operation. On
contention a thread tries to *exchange* on a randomly chosen slot within the
`EliminationArray`. On failure of such an *exchange* it loops to the beginning
retrying on the stack again.The result is a lock-free stack that is both _linearizable_ and _parallel_.
### Silly Benchmark
Criterion test comparing:
- `Arc>>`
- `TreiberStack`
- `EliminationBackoffStack` - Simply switching back and forth between stack and
elimination array.- `EliminationBackoffStack` - Exponentially backing off from the stack to the
elimination array both in space and time.X-Axis: Number of competing threads.
Y-Axis: Average time it took all threads to push and pop 1000 items each.

[1] Treiber, R. Kent. Systems programming: Coping with parallelism. New York:
International Business Machines Incorporated, Thomas J. Watson Research Center,
1986.