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 committed Nov 29, 2021
1 parent f45eee8 commit c912914
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rayon-core/src/thread_pool/mod.rs
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(&self) {
self.registry.terminate();
}
}

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

Expand Down

0 comments on commit c912914

Please sign in to comment.