Class ThreadPool

An object that manages worker threads and runs tasks on them

class ThreadPool ;

Constructors

NameDescription
this (maxThreads) Constructor

Methods

NameDescription
submit (taskDele) Create a task from delegate
submit (taskFunc) Create a task from function pointer
tasksDone () Returns true if all tasks are finished

Example

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);