ThreadPool

An object that manages worker threads and runs tasks on them

Constructors

this
this(uint maxThreads)

Constructor

Destructor

~this
~this()
Undocumented in source.

Members

Functions

isRunning
bool isRunning()
Undocumented in source. Be warned that the author may not have intended to support it.
request
Task request()
Undocumented in source. Be warned that the author may not have intended to support it.
submit
Task submit(void delegate() taskDele)

Create a task from delegate

submit
Task submit(void function() taskFunc)

Create a task from function pointer

tasksDone
bool tasksDone()

Returns true if all tasks are finished

Variables

maxThreads
uint maxThreads;
Undocumented in source.
mutex
Mutex mutex;
Undocumented in source.
running
bool running;
Undocumented in source.
taskQueue
TaskQueue taskQueue;
Undocumented in source.
workerThreads
WorkerThread[] workerThreads;
Undocumented in source.

Examples

import std.stdio;

int x = 0;
int y = 0;

void task1()
{
    while(x < 100)
        x += 1;
}

void task2()
{
    while(y < 100)
        y += 1;
}

ThreadPool threadPool = New!ThreadPool(2);

threadPool.submit(&task1);
threadPool.submit(&task2);

while(!threadPool.tasksDone) {}

if (x != 100) writeln(x);
if (y != 100) writeln(y);

assert(x == 100);
assert(y == 100);

Delete(threadPool);

Meta