1 unstable release
Uses new Rust 2024
| 0.1.4 | Nov 30, 2025 |
|---|
#1008 in Concurrency
80KB
1.5K
SLoC
High-performance queue primitives and Disruptor implementation for Kovan.
Features
ArrayQueue: Bounded MPMC queue.SegQueue: Unbounded MPMC queue (segment based).Disruptor: Disruptor pattern implementation.
Usage
use kovan_queue::disruptor::{Disruptor, EventHandler, BusySpinWaitStrategy};
struct MyEvent { data: u64 }
struct MyHandler;
impl EventHandler<MyEvent> for MyHandler {
fn on_event(&self, event: &MyEvent, _: u64, _: bool) {
println!("Event: {}", event.data);
}
}
let mut disruptor = Disruptor::builder(|| MyEvent { data: 0 })
.build();
disruptor.handle_events_with(MyHandler);
let mut producer = disruptor.start();
producer.publish(|e| e.data = 42);
What is Kovan?
Kovan solves the hardest problem in lock-free programming: when is it safe to free memory?
When multiple threads access shared data without locks, you can't just drop() or free() - another thread might still be using it. Kovan tracks this automatically with zero overhead on reads.
Why Kovan?
- Zero read overhead: Just one atomic load, nothing else
- Bounded memory: Never grows unbounded like epoch-based schemes
- Simple API: Three functions:
pin(),load(),retire()
Quick Start
[dependencies]
kovan = "0.1"
Basic Usage
use kovan::{Atomic, pin, retire};
use std::sync::atomic::Ordering;
// Create shared atomic pointer
let shared = Atomic::new(Box::into_raw(Box::new(42)));
// Read safely
let guard = pin(); // Enter critical section
let ptr = shared.load(Ordering::Acquire, &guard);
unsafe {
if let Some(value) = ptr.as_ref() {
println!("Value: {}", value);
}
}
drop(guard); // Exit critical section
// Update safely
let guard = pin();
let new_value = Box::into_raw(Box::new(100));
let old = shared.swap(
unsafe { kovan::Shared::from_raw(new_value) },
Ordering::Release,
&guard
);
// Schedule old value for reclamation
if !old.is_null() {
unsafe { retire(old.as_raw()); }
}
How It Works
pin()- Enter critical section, get a guardload()- Read pointer (zero overhead!)retire()- Schedule memory for safe reclamation
The guard ensures any pointers you load stay valid. When all guards are dropped, retired memory is freed automatically.
Examples
See the examples/ directory for complete implementations.
Performance
- 10x faster than naive implementations
- Competitive with Crossbeam-Epoch on reads
- Better memory bounds than epoch-based schemes
Optional Features
# Nightly optimizations (~5% faster)
kovan = { version = "0.1", features = ["nightly"] }
# Handle stalled threads
kovan = { version = "0.1", features = ["robust"] }
License
Licensed under Apache License 2.0.
Dependencies
~2.6–5MB
~97K SLoC