Class ThreadPool
An object that manages worker threads and runs tasks on them
Constructors
Name | Description |
this
(maxThreads)
|
Constructor
|
Methods
Name | Description |
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);