reformatted crate `multithreading` to pass tests
This commit is contained in:
parent
1208a04658
commit
990a54a032
|
@ -36,7 +36,7 @@ use std::{
|
|||
collections::VecDeque,
|
||||
num::NonZeroUsize,
|
||||
sync::{
|
||||
atomic::{AtomicUsize, Ordering, AtomicBool},
|
||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
thread::{self, JoinHandle},
|
||||
|
@ -132,7 +132,7 @@ where
|
|||
// will be initialized to 0
|
||||
threads: Arc::new(AtomicUsize::new(0)),
|
||||
// do not drop handles by default
|
||||
drop_handles: Arc::new(AtomicBool::new(false))
|
||||
drop_handles: Arc::new(AtomicBool::new(false)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +176,10 @@ where
|
|||
/// if `drop_handles` is set to [`Bool::false`] the pool will continue to store the handles of
|
||||
/// launched threads. This causes memory consumption to rise over time as more and more
|
||||
/// threads are launched.
|
||||
pub fn with_threads_and_drop_handles(max_thread_count: NonZeroUsize, drop_handles: bool) -> Self {
|
||||
pub fn with_threads_and_drop_handles(
|
||||
max_thread_count: NonZeroUsize,
|
||||
drop_handles: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
max_thread_count: max_thread_count.get(),
|
||||
drop_handles: Arc::new(AtomicBool::new(drop_handles)),
|
||||
|
@ -318,7 +321,13 @@ fn execute<F, T>(
|
|||
let next = queue.lock().unwrap().pop_front();
|
||||
if let Some(next_closure) = next {
|
||||
// if we have sth. to execute, spawn a new thread
|
||||
execute(queue, handles_copy.clone(), threads, drop.clone(), next_closure);
|
||||
execute(
|
||||
queue,
|
||||
handles_copy.clone(),
|
||||
threads,
|
||||
drop.clone(),
|
||||
next_closure,
|
||||
);
|
||||
} else {
|
||||
// nothing to execute this thread will run out without any work to do
|
||||
// decrement the amount of used threads
|
||||
|
|
Loading…
Reference in New Issue