ITaskExecuter

Associated with a group of related tasks that have been posted to the thread pool, making it easy to abort all the tasks or wait until all the tasks have been completed.


struct ITaskExecuter
{
    virtual void Close() = 0;
    virtual void PostTask(ThreadPoolTask task) = 0;
    virtual void Wait() = 0;
    virtual ssize_t GetNumRemainingTasks() const = 0;
protected:
    ~ITaskExecuter() {}
};


void Close()

A task executer must be closed when it is no longer in use. This implicitly calls Wait()


void PostTask(ThreadPoolTask task)

Call this function in order to have the given ThreadPoolTask executed by a worker thread some time in the future.

It is guaranteed that every call to PostTask is paired with a subsequent execution of the task.

If a thread is available the task will be assigned to the thread immediately. Otherwise the task is pushed onto a FIFO queue. There are no limits on the size of queue. Therefore it can be assumed this function will always return without blocking on task execution. The pool of worker threads pop tasks from the queue and executes them. There is no guarantee of the order in which the tasks are executed. However it can be assumed they will be more or less processed in the order they were posted.

This function is fully threadsafe - it is possible for multiple threads to call this function concurrently


void Wait()

Waits until the invocation of every task that's been posted so far has completed.


ssize_t GetNumRemainingTasks()

Returns the number of tasks that have been posted but not yet finished executing.