Skip to main content

PyZas!: A Python library for atomic integer operations

Project description

PyZas!: A Python library for atomic integer operations

PyZas is a Python library designed for performing atomic integer operations with the speed and efficiency of a zas! (Inspired by the sudden impact sound "zas" spanish onomatopoeia)). PyZas ensures your calculations are executed atomically and safely. Perfect for scenarios requiring quick, thread-safe manipulations.

Installation

You can install PyZas via pip:

pip install pyzas

Usage

The PyZas module implements the following atomic types:

  • AtomicInt: An atomic int type
  • AtomicLong: An atomic 64-bytes int type
  • AtomicULong: An atomic 64-bytes unsigned int type

The three types implement the following functions:

  • free_lock_level() -> int: Determines if the atomic object is implemented lock-free
  • load() -> int: Reads a value from an atomic object
  • store(int): Stores a value in an atomic object
  • exchange(int) -> int: Atomically replaces the value in an atomic object
  • fetch_add(int) -> int: Performs atomic addition
  • fetch_sub(int) -> int: Performs atomic subtraction
  • compare_exchange(int, int) -> int: Swaps a value with an atomic object if the old value is what is expected, otherwise reads the old value

Module also implements AtomicFlag with support for spinlock:

  • test_and_set() -> bool: sets an atomic flag to true and returns the old value
  • clear(): Sets the atomic_flag to false
  • spin_lock(): Causes a thread trying to acquire a lock to simply wait in a loop ("spin")
  • spin_unlock(): Releases the lock

For more details:

help(pyzas)

Example

import pyzas

n = pyzas.AtomicInt(0)
n.fetch_add(1)
print(n.load())

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

pyzas-1.0.tar.gz (42.1 kB view hashes)

Uploaded Source

Built Distributions

pyzas-1.0-cp313-cp313td-manylinux_2_31_x86_64.whl (41.3 kB view hashes)

Uploaded CPython 3.13td manylinux: glibc 2.31+ x86-64

pyzas-1.0-cp313-cp313td-manylinux_2_31_aarch64.whl (68.2 kB view hashes)

Uploaded CPython 3.13td manylinux: glibc 2.31+ ARM64

pyzas-1.0-cp313-cp313td-macosx_13_0_x86_64.whl (19.5 kB view hashes)

Uploaded CPython 3.13td macOS 13.0+ x86-64

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