License:
Author:
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // create a new pool with two threads auto pool = new ThreadPool!(int)(2); void delegate(int) f = (int x) { Log(x); }; // Now we have three ways of telling the pool to execute our jobs // First we can say we just want it done at some later point pool.append(f, 1); // Secondly we can ask for a job to be done as soon as possible, blocking // until it is started by some thread pool.assign(f, 2); // Finally we can say we either want it done immediately or not at all if (pool.tryAssign(f, 3)) Log("Someone took the job!"); else Log("No one was available to do the job right now"); // After giving the pool some jobs to do, we need to give it a chance to // finish, so we can do one of two things. // Choice no. 1 is to finish what has already been assigned to the threads, // but ignore any remaining queued jobs // pool.shutdown(); // The other choice is to finish all jobs currently executing or in queue: pool.finish(); |
Parameters:
workers | The amount of threads to spawn |
q_size | The expected size of the queue (how many elements are preallocated) |
Warning: