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 {
129
129
let idx = self . idx . fetch_add ( 1 , Ordering :: Relaxed ) ;
130
130
self . cqs [ idx % self . cqs . len ( ) ] . clone ( )
131
131
}
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
- }
143
132
}
144
133
145
134
impl Drop for Environment {
@@ -148,6 +137,15 @@ impl Drop for Environment {
148
137
// it's safe to shutdown more than once.
149
138
cq. shutdown ( )
150
139
}
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
+ }
151
149
}
152
150
}
153
151
@@ -174,6 +172,5 @@ mod tests {
174
172
}
175
173
176
174
assert_eq ! ( env. completion_queues( ) . len( ) , 2 ) ;
177
- env. shutdown_and_join ( ) ;
178
175
}
179
176
}
You can’t perform that action at this time.
0 commit comments