Skip to main content

A lock-free, thread-safe queue using the C++ atomic library to synchronise memory access.

Project description

atomic-queue

A thread-safe, lock-free queue implementation based on the LMAX Disruptor, with crititcal parts written in C++.

This queue supports multiple producers and consumers. Producers are responsible for managing their own threads, while consumer threads are managed by the queue and are required to implement the EventHandler interface.

Example

Initialise an atomic queue instance with the buffer capacity and a wait strategy. The buffer capacity must be a power of 2 integer.

from atomicqueue import AtomicQueue, BUSY_SPIN_WAIT_STRATEGY

queue = AtomicQueue(256, wait_strategy=BUSY_SPIN_WAIT_STRATEGY)

Define how the events will be consumed. In the example below event handler "h_one" and "h_two" can overrun each other but can not overrun the publishers, while event handler "h_three" can only consume events after "h_one" and "h_two" have finished consuming them.

queue.handle_events_with(NoOpEventHandler("h_one"), NoOpEventHandler("h_two")).then(NoOpEventHandler("h_three"))

Once configured the queue can be started with the following command.

queue.start()

To publish to the queue, simply call publish_event on the queue.

queue.publish_event(event)

Stop the queue by calling stop().

queue.stop()

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-queue-1.0.1.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file atomic-queue-1.0.1.tar.gz.

File metadata

  • Download URL: atomic-queue-1.0.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.6.11

File hashes

Hashes for atomic-queue-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4a0b9c84e3cea3f67b2ad42f86374766b12e1c0c1be8196d5a68dcec15befece
MD5 07c8ef146fc9441759180ea4ff60f8b4
BLAKE2b-256 0191ddd500fe9bcf8a6189899fe99f813985f509d48fbb138a691ee1b0a0dc6f

See more details on using hashes here.

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