[fpc-devel] Light weight threads for FPC
Florian Klaempfl
florian at freepascal.org
Fri Dec 14 10:20:28 CET 2007
Vinzent Hoefler schrieb:
> On Thursday 13 December 2007 19:55, Mattias Gaertner wrote:
>> Has someone already created a unit for light weight threads?
>>
>> Something like: Create a group of 4 threads named 0,1,2,3 and execute
>> a procedure/method?
>
> for i := 0 to 3 do
> Handle[i] := tThreadId(BeginThread (Func {tThreadFunc},
> @FuncArg[i]));
>
> for i := 0 to 3 do
> Result[i] := WaitForThreadTerminate (Handle[i], 0);
I think some thread pool class is more important, it would be basically
the same as above
for i := 0 to 3 do
Handle[i] := TTask(ThreadPool.QueueTask(Func {tThreadFunc},
@FuncArg[i]));
for i := 0 to 3 do
Result[i] := WaitForTask(Handle[i], 0);
but the threads are already idling and taking their tasks from a queue.
It allows also scaling with the cores: the more cores you have, the more
threads you put into your pool.
More information about the fpc-devel
mailing list