Inspired by CUDA, I would like to identify the index of each thread of a TThreadPool when used within a TParallel.For.
Consider the following non-compiling code:
var
v: Array of Integer;
APool: TThreadPool;
begin
APool:= TThreadPool.Create;
APool.SetMinWorkerThreads(10);
APool.SetMaxWorkerThreads(10);
SetLength(v, 10);
TParallel.For(0, 9, procedure(i: Integer)
begin
v[i]:= ThreadID; // Property ThreadId DOES NOT EXIST!
end, APool);
end;
How do I get the integer array v to store the index of the thread of the threadpool that has done the work? Of course, because there are 10 threads in the pool, the numbers in the array should range between 0 .. 9.