fn queue_job(&self, job: Box<dyn FnOnce() + Send>) {
        // We have a very simple model of worker threads. Each time a job is queued, we spin up a
        // new worker thread iff we aren't already running the maximum number of worker threads.
        // Once started, a worker thread never dies, waiting endlessly for work.

        let inner = Arc::clone(&self.inner);
        let (cv, mtx) = &inner.job_queue;
        mtx.lock().push_back(job);
        cv.notify_one();

        let max_jobs = inner.max_worker_threads.load(Ordering::Relaxed);
        if inner.active_worker_threads.load(Ordering::Relaxed) < max_jobs {
            // At the point of the `load` on the previous line, we weren't running the maximum
            // number of worker threads. There is now a possible race condition where multiple
            // threads calling `queue_job` could try creating multiple worker threads and push us
            // over the maximum worker thread limit.
            if inner.active_worker_threads.fetch_add(1, Ordering::Relaxed) > max_jobs {
                // Another thread(s) is also spinning up another worker thread and they won the
                // race.
                inner.active_worker_threads.fetch_sub(1, Ordering::Relaxed);
                return;
            }

            let inner_cl = Arc::clone(&self.inner);
            thread::spawn(move || {
                let (cv, mtx) = &inner_cl.job_queue;
                let mut lock = mtx.lock();
                loop {
                    match lock.pop_front() {
                        Some(x) => MutexGuard::unlocked(&mut lock, x),
                        None => cv.wait(&mut lock),
                    }
                }
            });
        }
    }
/// Queue `job` to be run on a worker thread.
Queue `job` to be run on a worker thread.
Queue ` job ` to be run on a worker thread .
fn queue_job(&self, job: Box<dyn FnOnce() + Send>) {
        // We have a very simple model of worker threads. Each time a job is queued, we spin up a
        // new worker thread iff we aren't already running the maximum number of worker threads.
        // Once started, a worker thread never dies, waiting endlessly for work.
        let inner = Arc::clone(&self.inner);
        let (cv, mtx) = &inner.job_queue;
        mtx.lock().push_back(job);
        cv.notify_one();
        let max_jobs = inner.max_worker_threads.load(Ordering::Relaxed);
        if inner.active_worker_threads.load(Ordering::Relaxed) < max_jobs {
            // At the point of the `load` on the previous line, we weren't running the maximum
            // number of worker threads. There is now a possible race condition where multiple
            // threads calling `queue_job` could try creating multiple worker threads and push us
            // over the maximum worker thread limit.
            if inner.active_worker_threads.fetch_add(1, Ordering::Relaxed) > max_jobs {
                // Another thread(s) is also spinning up another worker thread and they won the
                // race.
                inner.active_worker_threads.fetch_sub(1, Ordering::Relaxed);
                return;
            }
            let inner_cl = Arc::clone(&self.inner);
            thread::spawn(move || {
                let (cv, mtx) = &inner_cl.job_queue;
                let mut lock = mtx.lock();
                loop {
                    match lock.pop_front() {
                        Some(x) => MutexGuard::unlocked(&mut lock, x),
                        None => cv.wait(&mut lock),
                    }
                }
            });
        }
    }
fn queue_job ( & self , job : Box < dyn FnOnce ( ) + Send > ) { // We have a very simple model of worker threads. Each time a job is queued, we spin up a // new worker thread iff we aren't already running the maximum number of worker threads. // Once started, a worker thread never dies, waiting endlessly for work. let inner = Arc :: clone ( & self . inner ) ; let ( cv , mtx ) = & inner . job_queue ; mtx . lock ( ) . push_back ( job ) ; cv . notify_one ( ) ; let max_jobs = inner . max_worker_threads . load ( Ordering :: Relaxed ) ; if inner . active_worker_threads . load ( Ordering :: Relaxed ) < max_jobs { // At the point of the `load` on the previous line, we weren't running the maximum // number of worker threads. There is now a possible race condition where multiple // threads calling `queue_job` could try creating multiple worker threads and push us // over the maximum worker thread limit. if inner . active_worker_threads . fetch_add ( 1 , Ordering :: Relaxed ) > max_jobs { // Another thread(s) is also spinning up another worker thread and they won the // race. inner . active_worker_threads . fetch_sub ( 1 , Ordering :: Relaxed ) ; return ; } let inner_cl = Arc :: clone ( & self . inner ) ; thread :: spawn ( move | | { let ( cv , mtx ) = & inner_cl . job_queue ; let mut lock = mtx . lock ( ) ; loop { match lock . pop_front ( ) { Some ( x ) => MutexGuard :: unlocked ( & mut lock , x ) , None => cv . wait ( & mut lock ) , } } } ) ; } }
Queue `job` to be run on a worker thread.
Queue ` job ` to be run on a worker thread .
&self
job
Box<dyn FnOnce() + Send>
&self
job
Box<dyn FnOnce() + Send>