From 1f604e7eac3018785c98429139ed10281b2a7f35 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Fri, 3 Jun 2022 19:51:51 -0600 Subject: [PATCH] Only use one thread with Tokio When Tokio gets event notification from kevent, the pending future may belong to a different thread. If so, it signals the other thread and pends on kevent again. But the other thread may not have had time to call aio_return yet. In that case, the first thread's kevent will immediately return again. The correct solution is to set EV_ONESHOT on the aiocb. But Rust's libc doesn't currently expose the necessary field. Until it does, restrict Tokio to just a single thread. https://github.com/rust-lang/libc/pull/2813 --- bfffs-fio/src/lib.rs | 2 +- bfffs/benches/fs_destroy.rs | 2 +- bfffs/src/bin/bfffsd/main.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bfffs-fio/src/lib.rs b/bfffs-fio/src/lib.rs index a37d9d2e..32d7e500 100644 --- a/bfffs-fio/src/lib.rs +++ b/bfffs-fio/src/lib.rs @@ -166,7 +166,7 @@ pub extern "C" fn rust_ctor() { lazy_static! { static ref RUNTIME: RwLock = RwLock::new( - Builder::new_multi_thread() + Builder::new_current_thread() .enable_time() .enable_io() .build() diff --git a/bfffs/benches/fs_destroy.rs b/bfffs/benches/fs_destroy.rs index 6f37064f..b5e2b2ca 100644 --- a/bfffs/benches/fs_destroy.rs +++ b/bfffs/benches/fs_destroy.rs @@ -316,7 +316,7 @@ fn fs_destroy( Ok(()) } -#[tokio::main] +#[tokio::main(flavor = "current_thread")] async fn main() -> Result<()> { tracing_subscriber::fmt() .pretty() diff --git a/bfffs/src/bin/bfffsd/main.rs b/bfffs/src/bin/bfffsd/main.rs index 5d1f5f2b..08fa2edf 100644 --- a/bfffs/src/bin/bfffsd/main.rs +++ b/bfffs/src/bin/bfffsd/main.rs @@ -353,7 +353,7 @@ impl Bfffsd { } } -#[tokio::main] +#[tokio::main(flavor = "current_thread")] async fn main() { tracing_subscriber::fmt() .pretty()