#channel #broadcast #lock-free

bus

A lock-free, bounded, single-producer, multi-consumer, broadcast channel

23 stable releases

2.4.1 Aug 20, 2023
2.4.0 Mar 25, 2023
2.3.0 Jul 2, 2022
2.2.3 Mar 3, 2020
0.2.1 Jun 3, 2016

#36 in Concurrency

Download history 1930/week @ 2023-10-31 2091/week @ 2023-11-07 2335/week @ 2023-11-14 1995/week @ 2023-11-21 2863/week @ 2023-11-28 2399/week @ 2023-12-05 2840/week @ 2023-12-12 1933/week @ 2023-12-19 1241/week @ 2023-12-26 2365/week @ 2024-01-02 2276/week @ 2024-01-09 2474/week @ 2024-01-16 2279/week @ 2024-01-23 2269/week @ 2024-01-30 2509/week @ 2024-02-06 2065/week @ 2024-02-13

9,489 downloads per month
Used in 28 crates (26 directly)

MIT/Apache

40KB
433 lines

bus

Crates.io Documentation Codecov

Bus provides a lock-free, bounded, single-producer, multi-consumer, broadcast channel.

NOTE: bus sometimes busy-waits in the current implementation, which may cause increased CPU usage — see #23.

It uses a circular buffer and atomic instructions to implement a lock-free single-producer, multi-consumer channel. The interface is similar to that of the std::sync::mpsc channels, except that multiple consumers (readers of the channel) can be produced, whereas only a single sender can exist. Furthermore, in contrast to most multi-consumer FIFO queues, bus is broadcast; every send goes to every consumer.

I haven't seen this particular implementation in literature (some extra bookkeeping is necessary to allow multiple consumers), but a lot of related reading can be found in Ross Bencina's blog post "Some notes on lock-free and wait-free algorithms".

See the documentation for usage examples.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.5–6.5MB
~12K SLoC