std1.0.0-beta-7 SafeC docs

std :: async::pool

Struct std::ThreadPool

#include <std/async/pool.h> source

struct ThreadPool {
    unsigned long long mu;
    unsigned long long work_cv;
    unsigned long long done_cv;
    ?&TaskHeader qhead;
    ?&TaskHeader qtail;
    int live;
    int stopping;
    int nthreads;
    int idle;
    unsigned long long tids[ASYNC_POOL_MAX_THREADS];
    struct TimerQueue timers;
    long long polls;
}

Fields

§unsigned long long musource

guards the queue, live, the flags

§unsigned long long work_cvsource

signalled when a task is queued (or on shutdown)

§unsigned long long done_cvsource

broadcast when a task finishes

run queue, linked through TaskHeader::next

§int livesource

spawned and not finished

§int stoppingsource
§int nthreadssource
§int idlesource

workers waiting for work

§unsigned long long tids[ASYNC_POOL_MAX_THREADS]source
§struct TimerQueue timerssource
§long long pollssource

statistics

Methods

§static struct ThreadPool new()source · definition

A pool with no threads yet. Put it where it will stay, then start().

§int start(int n)source · definition

Start 'n' worker threads (1..ASYNC_POOL_MAX_THREADS). 0 on success.

§generic<F: Send, T: Send> struct JoinHandle<T> spawn(&AsyncTask<F, T> task)source · definition

F and T must be Send: the task runs (and finishes) on a worker thread.

§generic<F: Future + Send, T: Send> T block_on(F fut)source · definition

Run 'fut' as a task on the pool and wait (this thread blocks) for its value. Call from outside the pool's workers.

§void wait_idle()source · definition

Block until every spawned task has finished.

§void drop()source · definition

Stop the workers (after their current poll) and join them. Tasks still queued or waiting are abandoned, not dropped.

§void shutdown() consumesource · definition

= drop()

§int live_count()source · definition