@@ -95,27 +95,31 @@ fn maybe_create_another_blocking_thread() {
95
95
return ;
96
96
}
97
97
98
- // We want to avoid having all threads terminate at
99
- // exactly the same time, causing thundering herd
100
- // effects. We want to stagger their destruction over
101
- // 10 seconds or so to make the costs fade into
102
- // background noise.
103
- //
104
- // Generate a simple random number of milliseconds
105
- let rand_sleep_ms = u64:: from ( random ( 10_000 ) ) ;
98
+ let n_to_spawn = std:: cmp:: min ( 2 + ( workers / 10 ) , 10 ) ;
106
99
107
- thread:: Builder :: new ( )
108
- . name ( "async-std/blocking" . to_string ( ) )
109
- . spawn ( move || {
110
- let wait_limit = Duration :: from_millis ( 1000 + rand_sleep_ms) ;
100
+ for _ in 0 ..n_to_spawn {
101
+ // We want to avoid having all threads terminate at
102
+ // exactly the same time, causing thundering herd
103
+ // effects. We want to stagger their destruction over
104
+ // 10 seconds or so to make the costs fade into
105
+ // background noise.
106
+ //
107
+ // Generate a simple random number of milliseconds
108
+ let rand_sleep_ms = u64:: from ( random ( 10_000 ) ) ;
111
109
112
- DYNAMIC_THREAD_COUNT . fetch_add ( 1 , Ordering :: Relaxed ) ;
113
- while let Ok ( task) = POOL . receiver . recv_timeout ( wait_limit) {
114
- abort_on_panic ( || task. run ( ) ) ;
115
- }
116
- DYNAMIC_THREAD_COUNT . fetch_sub ( 1 , Ordering :: Relaxed ) ;
117
- } )
118
- . expect ( "cannot start a dynamic thread driving blocking tasks" ) ;
110
+ thread:: Builder :: new ( )
111
+ . name ( "async-std/blocking" . to_string ( ) )
112
+ . spawn ( move || {
113
+ let wait_limit = Duration :: from_millis ( 1000 + rand_sleep_ms) ;
114
+
115
+ DYNAMIC_THREAD_COUNT . fetch_add ( 1 , Ordering :: Relaxed ) ;
116
+ while let Ok ( task) = POOL . receiver . recv_timeout ( wait_limit) {
117
+ abort_on_panic ( || task. run ( ) ) ;
118
+ }
119
+ DYNAMIC_THREAD_COUNT . fetch_sub ( 1 , Ordering :: Relaxed ) ;
120
+ } )
121
+ . expect ( "cannot start a dynamic thread driving blocking tasks" ) ;
122
+ }
119
123
}
120
124
121
125
// Enqueues work, attempting to send to the threadpool in a
0 commit comments