Skip to main content

easy-to-use lock-free atomic integers and booleans for multithreading

Project description

atomicx

PyPI version

atomicx is an easy-to-use atomics library for Python, providing atomic integer and boolean operations. It allows you to perform atomic operations on shared variables, ensuring thread-safety and preventing race conditions in concurrent programming. Everything is entirely lock-free and is backed by Rust's atomic types.

Features

  • Atomic integer operations: load, store, add, subtract, swap, compare and exchange, multiply, divide, increment, decrement.
  • Atomic boolean operations: load, store, swap, compare and exchange, flip.

Installation

Binary wheels are provided for Python 3.7 and above on Linux, macOS, and Windows:

pip install atomicx

Usage

See the documentation for more information. Here's a quick overview:

Atomic Integer

from atomicx import AtomicInt

# Create an atomic integer with an initial value of 0
atom = AtomicInt()

# Perform atomic operations
atom.store(10)
value = atom.load()
print(f"Value: {value}")

previous_value = atom.swap(20)
print(f"Previous Value: {previous_value}")

atom.add(5)
print(f"Result after addition: {atom}")

# Increment and decrement operations
atom.inc()
atom.dec()

Atomic Boolean

from atomicx import AtomicBool

# Create an atomic boolean with an initial value of False
atom = AtomicBool()

# Perform atomic operations
atom.store(True)
value = atom.load()
print(f"Value: {value}")

previous_value = atom.swap(False)
print(f"Previous Value: {previous_value}")

result = atom.compare_exchange(False, True)
print(f"Swap Result: {result}")

# Flip the value of the atomic boolean
atom.flip()

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • The atomicx library is heavily dependent on and inspired by the Rust std::sync::atomic module.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atomicx-0.0.12.tar.gz (9.2 kB view details)

Uploaded Source

Built Distributions

atomicx-0.0.12-cp37-abi3-win_amd64.whl (137.6 kB view details)

Uploaded CPython 3.7+ Windows x86-64

atomicx-0.0.12-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

atomicx-0.0.12-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (512.4 kB view details)

Uploaded CPython 3.7+ macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

File details

Details for the file atomicx-0.0.12.tar.gz.

File metadata

  • Download URL: atomicx-0.0.12.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.1.0

File hashes

Hashes for atomicx-0.0.12.tar.gz
Algorithm Hash digest
SHA256 6f41b8a0b09844682d998e99585ce18e321fd316bf60061cba06b2f4e1ac26c5
MD5 039f16b3843885419a50ab8cd7b21107
BLAKE2b-256 cf065bb4fe5e88ae90cc0fe43a35a461d7a01255f682be99ac645cc9dc2128b9

See more details on using hashes here.

Provenance

File details

Details for the file atomicx-0.0.12-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for atomicx-0.0.12-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0f4c350117eb78fcc9901c11015a2e0984b4f7628c8ab714321b4740322637c3
MD5 b02c2e96cbced06ffe1b350845738308
BLAKE2b-256 5b4db5557070fd3dd65d257e1dd431e88eab3648655403cfd7f49698a4076b9d

See more details on using hashes here.

Provenance

File details

Details for the file atomicx-0.0.12-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for atomicx-0.0.12-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8b6c01d28f2c88a48bcf6cd58d37d59d81c14080e93956c40145e30225b234c9
MD5 0b8b93dd95fa4c7031dd9654c0230574
BLAKE2b-256 e207170bf6e12c78b7a89a8710aa76a563437ffa21b0a8c3fe1f6ec64d7ecddb

See more details on using hashes here.

Provenance

File details

Details for the file atomicx-0.0.12-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for atomicx-0.0.12-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 429ab90d958a71eb63d706b5da9c4b04122a130cb146d1b418e5e2d13d33e83b
MD5 8b5f618f3c593e7730acbc553bfce3b1
BLAKE2b-256 5bcdef9e394bf07ae6c1fadca8c3e94b7c09a81115885327fe2ec456e4e629de

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page