Crates.io | rs_lockfree |
lib.rs | rs_lockfree |
version | 0.1.1 |
source | src |
created_at | 2018-05-16 11:42:06.658782 |
updated_at | 2018-06-06 07:04:29.491637 |
description | a lock-Free lib based on practical Hazard Pointers algorithm |
homepage | |
repository | https://github.com/solotzg/rs-lockfree.git |
max_upload_size | |
id | 65681 |
size | 95,601 |
Concurrently R/W Shared Object
is one of the most frequent operations in high performance concurrent program.
There are several ways to implement it, such as R/W Lock
, Reference Counting
, Hazard Pointers
, Epoch Based Reclamation
,
Quiescent State Based Reclamation
.Hazard Pointers
algorithm firstly saves the
pointer of shared object to local thread, and then accessed it, and removes it after accessing is over. An object can
be released only when there is no thread contains its reference, which solve the ABA problem
.So far, this lib only supports x86_64
arch because there are few scenes other than high-performance server program need
lock-free solution.
Because of False sharing
, a part of the member variables, might be
frequently modified by different threads, are aligned to 64 bytes. And this may lead to stack overflow while initializing.
So, 3 features are provided in Cargo.toml
: max_thread_count_16(default), max_thread_count_256,
max_thread_count_4096(need to manually change minimum stack size or set RUST_MIN_STACK to 6000000).
Most allocators chose 128K(default setting) as the threshold to decide whether to allocate memory by mmap
. In
order to improve performance, it's better to allocate HazardEpoch
, LockFreeQueue
or LockFreeStack
in stack.
Examples
example_hazard_epoch
show the scene that multiple producers and multiple reader deal with one config. Run command:
RUST_LOG=INFO cargo run --release --example example_hazard_epoch
example_lockfree_queue
show the scene with multiple producers and multiple consumers. Run command:
RUST_LOG=INFO cargo run --release --example example_lockfree_queue
example_lockfree_stack
show the scene with multiple producers and multiple consumers. Run command:
RUST_LOG=INFO cargo run --release --example example_lockfree_stack
0.1.1
allocator_api
, because rust-nightly changes this feature too damn frequently.