HybridFutex
is a Rust library that provides a synchronization primitive that allows threads to wait for a notification from another thread. It is designed to be low-overhead and scalable and supports both synchronous and asynchronous waiting and notification.
To use HybridFutex
, simply add it as a dependency in your Cargo.toml
file:
toml
[dependencies]
hybrid-futex = "0.1"
Then, you can use HybridFutex
in your Rust code as follows:
```rust use std::sync::Arc; use std::thread; use std::time::Duration; use hybridfutex::HybridFutex;
let waitqueue = Arc::new(HybridFutex::new()); let waitqueueclone = waitqueue.clone();
// Spawn a thread that waits for a notification from another thread let handle = thread::spawn(move || { println!("Thread 1 is waiting"); waitqueueclone.wait_sync(); println!("Thread 1 is notified"); });
// Wait for a short time before notifying the other thread thread::sleep(Duration::from_millis(100));
// Notify the other thread waitqueue.notifyone();
// Wait for the other thread to finish handle.join().unwrap(); ```
This project is licensed under the MIT License - see the LICENSE file for details.