Skip to content

Commit

Permalink
Ability to terminate thread-pool upon shutdown
Browse files Browse the repository at this point in the history
While `.terminate()` will leave the thread-pool in corrupt state, it helps debugging and testing.
  • Loading branch information
alippai authored Nov 29, 2021
1 parent f45eee8 commit ecf4e3c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rayon-core/src/thread_pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,18 @@ impl ThreadPool {
// We assert that `self.registry` has not terminated.
unsafe { spawn::spawn_fifo_in(op, &self.registry) }
}

/// Terminates the threads, renders the threadpool unusable.
/// This is useful for testing (miri) if the thread-pool is static.
/// It should be used upon shutdown only
pub fn terminate(&mut self) {
self.registry.terminate();
}
}

impl Drop for ThreadPool {
fn drop(&mut self) {
self.registry.terminate();
self.terminate();
}
}

Expand Down

0 comments on commit ecf4e3c

Please sign in to comment.