From 78931cc1e21ff53ff8bb51b4006b1b6d8d5e577d Mon Sep 17 00:00:00 2001 From: Braulio Valdivielso Date: Sun, 12 Dec 2021 20:17:23 +0000 Subject: [PATCH] add comment to start discussion --- tokio/src/runtime/blocking/pool.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tokio/src/runtime/blocking/pool.rs b/tokio/src/runtime/blocking/pool.rs index 77ab4958683..f122257e520 100644 --- a/tokio/src/runtime/blocking/pool.rs +++ b/tokio/src/runtime/blocking/pool.rs @@ -270,6 +270,10 @@ impl Inner { shared.num_idle += 1; while !shared.shutdown { + // NOTE: A task spawned by spawn_blocking if: + // 1. It is spawned (thus the `condvar` gets a `notify_one`) + // 2. `shutdown` is called and manages to acquire the `shared.lock` *before* the + // thread woken up here gets a hold of it. Then `shutdown` will be true. let lock_result = self.condvar.wait_timeout(shared, self.keep_alive).unwrap(); shared = lock_result.0;