Fix a possible test hang in runtime::test_shared_buffer_sweep (#25545)

* Fix a possible test hang in runtime::test_shared_buffer_sweep

The test may hang if the total number of threads it wants to start
is greater than the number of threads configured in the rayon
threadpool. Check to avoid this situation from happening.

* Incorporate comment from Xiang Zhu, using std::cmp::min() to simplify the code
This commit is contained in:
Wei Hu 2022-05-30 23:39:32 +08:00 committed by GitHub
parent d4e7ebf4f8
commit 4b1dd0f921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -844,7 +844,9 @@ pub mod tests {
let parallel_reader = reader_ct > 2; let parallel_reader = reader_ct > 2;
let handle = if parallel_reader { let handle = if parallel_reader {
let threads = 8; // Avoid to create more than the number of threads available in the
// current rayon threadpool. Deadlock could happen otherwise.
let threads = std::cmp::min(8, rayon::current_num_threads());
Some({ Some({
let parallel = (0..threads) let parallel = (0..threads)
.into_iter() .into_iter()