futex-queue
An efficient MPSC queue with timer capability based on Linux futex. Suitable for real-time applications.
How it Works
Queue is based on Linux futex syscall to wait for both immediate and scheduled items in a single syscall. This alleviates the need for separate timer thread, which would involve multiple context switches.
Immediate items are sent via regular futex atomic variable waking mechanism. Scheduled items use FUTEX_WAIT_BITSET
operation with absolute timestamp of the earliest item in the queue as a timeout for the syscall.
Example
let = new;
let now = now;
let thread = spawn;
tx.send.unwrap;
tx.send_scheduled.unwrap;
tx.send.unwrap;
tx.send_scheduled.unwrap;
thread.join.unwrap;
Output:
0 ms: Received: 3
0 ms: Received: 1
1000 ms: Received: 2
2000 ms: Received: 4