Skip to content

A lock-free, thread-safe sequence/counter which uses the C++ atomic library under the hood. This gives a ~5-10x speed up compared to threading locks.

License

Notifications You must be signed in to change notification settings

arossoshynskyy/atomic-sequence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Atomic Sequence

A lock-free, thread-safe sequence/counter which uses the C++ atomic library under the hood. This gives a ~5-10x speed up compared to threading locks.

Install

pip install atomic-sequence

Usage

from atomicsequence import AtomicSequence

sequence = AtomicSequence(0)

# set current sequence value to 1
sequence.set(1)

# get current value
value = sequence.get()

# increment the sequence value and get the new value
value = sequence.increment_and_get(1)

# increment the sequence value and get the value directly preceding the operation
value = sequence.get_and_increment(1)

Testing

To run unittests and benchmarks use tox:

pipenv install --dev
pipenv run tox

About

A lock-free, thread-safe sequence/counter which uses the C++ atomic library under the hood. This gives a ~5-10x speed up compared to threading locks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published