File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff 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
145134impl 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}
You can’t perform that action at this time.
0 commit comments