Skip to main content

A library for lock-free shared 64-bit dictionaries

Project description

Atomic-Dict: A library for lock-free shared 64-bit dictionaries

Atomic-Dict provides a shared Map[Int, Int] for 64-bit integer values. Create an AtomicDict(), fork, then update keyed values using atomic operations. Supported operations include compare-and-swap, exchange, increment, etc.

Limitations

This is not a general purpose dictionary implementation. It is designed to be used as a synchronization primitive. Key limitations include:

  • The key must be a non-zero 64-bit value.
  • The value for freshly allocated keys are always initialized as 0.
  • Keys allocated into the dictionary can never be removed.
  • The maximum size of the dictionary must be specified upfront.

To support more complex types, build shared a list[XYZ] before fork(), then use indexes into those lists as the keys and values of the AtomicDict.

Performance

While bare bones, AtomicDict is fast. Operations never lock, never wait, and leverage cache locality. It is hard to imagine a faster shared dictionary implementation.

Example use

from atomic_dict import AtomicDict
import multiprocessing

if __name__ == "__main__":
  dict = AtomicDict(1024*1024)
  context = multiprocessing.get_context("fork")
  def worker(id: int) -> None:
      for _ in range(32*1024):
          idx = dict[1].add(1) # also: sub, bor, bxor, band, swap, cas(expected, replacement)
          dict[100 + idx] = id
  with context.Pool(8) as p:
      p.map(worker, range(16))

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

atomic_dict-0.5.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

atomic_dict-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl (35.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

atomic_dict-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl (43.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

atomic_dict-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl (41.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

File details

Details for the file atomic_dict-0.5.0.tar.gz.

File metadata

  • Download URL: atomic_dict-0.5.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.6 Linux/4.18.0-513.24.1.el8_9.x86_64

File hashes

Hashes for atomic_dict-0.5.0.tar.gz
Algorithm Hash digest
SHA256 9eefe28c4acf5a96aa4555ac177f684685cd43ec0932bf30a317f73edc5846b4
MD5 4aec5cbece1b69e01b012ba9af0f1d9c
BLAKE2b-256 808d473b6829d5adfb237431c4ac2d6a6f02a7cb6294030dcbbc620613055061

See more details on using hashes here.

File details

Details for the file atomic_dict-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: atomic_dict-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: CPython 3.14, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Linux/4.18.0-553.81.1.el8_10.x86_64

File hashes

Hashes for atomic_dict-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 65b2d0e5b2da7fd5b5ab51a11369987c56fb229e8d998b883abdafd4ba2dca42
MD5 b66014a47c45413bdda58405c4eadb98
BLAKE2b-256 406b81ec012c291f5c015e3aab09eaa9764961dbf163a541f990fc7e06448524

See more details on using hashes here.

File details

Details for the file atomic_dict-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: atomic_dict-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: CPython 3.13, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Linux/4.18.0-513.24.1.el8_9.x86_64

File hashes

Hashes for atomic_dict-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9cf26053b59412ae380f4dd033b7c3ce24c612e470cd96c10a22b7ecedb73190
MD5 404734cd7c9f827b9a96d1a7e018a66c
BLAKE2b-256 bed46554ab9f7cdb9ba3d204c9815aec6b78e91371b0a178f5e147f8927eabac

See more details on using hashes here.

File details

Details for the file atomic_dict-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: atomic_dict-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 41.9 kB
  • Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.6 Linux/4.18.0-513.24.1.el8_9.x86_64

File hashes

Hashes for atomic_dict-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3190da3aeb4e689729f05256b7eb21b69186a462e9af7dd5a1e1e9fbaf2264dd
MD5 74ecbadb93b4ed2ef2e76cecb9642bc4
BLAKE2b-256 358d4491515cc120c48d8999e9a83bf65800479cf9a23a7561dc95b65d4170ba

See more details on using hashes here.

Supported by

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