Skip to content

Commit

Permalink
Only use one thread with Tokio
Browse files Browse the repository at this point in the history
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.

rust-lang/libc#2813
  • Loading branch information
asomers committed Jun 4, 2022
1 parent c1dd649 commit 1f604e7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bfffs-fio/src/lib.rs
Expand Up @@ -166,7 +166,7 @@ pub extern "C" fn rust_ctor() {

lazy_static! {
static ref RUNTIME: RwLock<Runtime> = RwLock::new(
Builder::new_multi_thread()
Builder::new_current_thread()
.enable_time()
.enable_io()
.build()
Expand Down
2 changes: 1 addition & 1 deletion bfffs/benches/fs_destroy.rs
Expand Up @@ -316,7 +316,7 @@ fn fs_destroy(
Ok(())
}

#[tokio::main]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
tracing_subscriber::fmt()
.pretty()
Expand Down
2 changes: 1 addition & 1 deletion bfffs/src/bin/bfffsd/main.rs
Expand Up @@ -353,7 +353,7 @@ impl Bfffsd {
}
}

#[tokio::main]
#[tokio::main(flavor = "current_thread")]
async fn main() {
tracing_subscriber::fmt()
.pretty()
Expand Down

0 comments on commit 1f604e7

Please sign in to comment.