Skip to content

Commit 452e447

Browse files
committed
Instead of previous commit, join worker threads in drop
Includes a test for whether any of them is the current thread before joining. Signed-off-by: Chris Beck <[email protected]>
1 parent 154050d commit 452e447

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/env.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,6 @@ impl Environment {
129129
let idx = self.idx.fetch_add(1, Ordering::Relaxed);
130130
self.cqs[idx % self.cqs.len()].clone()
131131
}
132-
133-
/// Shutdown the completion queues and join all threads
134-
pub fn shutdown_and_join(&mut self) {
135-
for cq in self.completion_queues() {
136-
cq.shutdown();
137-
}
138-
139-
for handle in self._handles.drain(..) {
140-
handle.join().unwrap();
141-
}
142-
}
143132
}
144133

145134
impl Drop for Environment {
@@ -148,6 +137,15 @@ impl Drop for Environment {
148137
// it's safe to shutdown more than once.
149138
cq.shutdown()
150139
}
140+
141+
// Join our threads when we leave scope
142+
// Try not to join the current thread
143+
let current_thread_id = std::thread::current().id();
144+
for handle in self._handles.drain(..) {
145+
if handle.thread().id() != current_thread_id {
146+
handle.join().unwrap();
147+
}
148+
}
151149
}
152150
}
153151

@@ -174,6 +172,5 @@ mod tests {
174172
}
175173

176174
assert_eq!(env.completion_queues().len(), 2);
177-
env.shutdown_and_join();
178175
}
179176
}

0 commit comments

Comments
 (0)