Skip to main content

Crate kovan_channel

Crate kovan_channel 

Source
Expand description

Multi-producer multi-consumer channels using Kovan for memory reclamation.

This crate provides high-performance, lock-free channel implementations built on top of the Kovan memory reclamation system. It offers both unbounded and bounded channels, along with a powerful select! macro for concurrent operations.

§Key Features

  • Multi-producer Multi-consumer (MPMC): All channels support multiple concurrent senders and receivers.
  • Lock-Free Operations: Core operations are lock-free, ensuring system-wide progress.
  • Blocking Support: Channels support blocking send (when full) and recv (when empty) operations.
  • Select Macro: A select! macro for waiting on multiple channel operations, including a default case.
  • Special Channels: Includes after, tick, and never channels for timing and control flow.
  • Kovan Integration: Uses Kovan’s safe memory reclamation to manage channel nodes without garbage collection.

§Channel Flavors

  • unbounded(): A channel with infinite capacity. It never blocks on send, but can block on receive.
  • bounded(): A channel with fixed capacity. It blocks on send when full and on receive when empty.

§Example

use kovan_channel::unbounded;

let (s, r) = unbounded::<i32>();
s.send(10);
assert_eq!(r.try_recv(), Some(10));

§Platform support

Blocking APIs (bounded::Sender::send, recv/recv_deadline on both flavors, select! without a default arm, after, tick) are native-only and gated out on wasm32-* targets, where parking a thread is unsupported (wasm32-unknown-unknown/wasm32-wasip1 panic on thread::park/thread::sleep/Instant::now/SystemTime::now, and both are single-threaded so a park could never be woken anyway). See signal::Signal for a blocking-select! example. wasm builds keep the non-blocking surface: try_recv, send_async/recv_async, unbounded::Sender::send, select! with a default arm, and never.

§Safety

This crate uses unsafe code internally for performance and to interface with the Kovan memory reclamation system. However, it exposes a safe API. Memory safety is guaranteed by Kovan’s epoch-based reclamation, ensuring that nodes are only freed when no threads are accessing them.

Re-exports§

pub use flavors::RecvDeadline;
pub use flavors::bounded;
pub use flavors::unbounded;
pub use flavors::after::after;
pub use flavors::never::never;
pub use flavors::tick::tick;

Modules§

flavors
Channel flavors (unbounded, bounded, special).
select
Select macro implementation.
signal
Signal mechanism for thread synchronization. Thread and task wakeup primitives.

Macros§

select
Waits on multiple concurrent branches.

Functions§

bounded
Creates a channel of bounded capacity.
set_timer
Installs the timer a task awaiting a channel of after or tick sleeps on until its message is due; with none, such a task asks to be polled again and again until then. A runtime calls it once, at its start; answers whether this call installed the timer (the first one does, and it stays for the life of the process).
unbounded
Creates a channel of unbounded capacity.

Type Aliases§

Timer
A runtime’s timer, for the channels of after and tick: called with a due instant and a task’s waker, it wakes the waker once that instant has passed (at once if it already has), from any thread.