[fpc-devel] Light weight threads for FPC

Eric Grange egrange at infonie.fr
Fri Dec 14 11:37:53 CET 2007

 > What do you mean by "light weight threads" ? How can it get "lighter" 
than TThread,
 >that offers close to no built-in "comfort"-functionality ?

TThread (and BeginThread) are quite heavy for small tasks, not because 
of the Pascal code, but because of the OS overhead involved in creating, 
starting and cleaning up a thread.
Florian's ThreadPool suggestion is what "lightweight" threads could be 

Also a construct like

 > for i := 0 to 3 do
 >    Result[i] := WaitForTask(Handle[i], 0);

isn't very desirable, as it involves polling and can result in multiple 
thread switchings.
A WaitForMultipleTasks(...some task handle list...) is a more preferable 
approach, as it can be mapped to OS functions such as 
WaitForMultipleObjects under windows, which will hopefully handle it at 
the kernel/thread scheduling level.


More information about the fpc-devel mailing list