[Lazarus] Threads in Lazarus code base

Michael Schnell mschnell at lumino.de
Wed Sep 15 13:56:54 CEST 2010

  On 09/15/2010 12:46 PM, Michael Van Canneyt wrote:
> What is so performance killing about process messages ?
process message is a function call that obviously take some microseconds 
to run. Thus, if you do it very often, it degrades the overall 
performance, if you do it rather seldom, the latency of the other tasks 
the program needs to do degrades
> What do you think the OS does when switching threads ? A thread switch
> is much more expensive than a "process messages".
Of course the OS needs much more time to switch threads than process 
messages needs "program tasks". But the OS does not need to do polling. 
Threads are only switched when needed while process messages needs to be 
called very frequently for a decent latency and nearly all calls are in 
>> how do you make a program doing huge calculations use multiple CPUs
>> which are the contrary of "of the past" ?
> I didn't claim to have a better solution. I just observed that the
> very idea of threads is basically flawed.
That is why I started my answer with "OK" .)
> These are not my words, but the conclusion of scientific research on
> the subject.
There are several decent scientific research papers that bash threads. 
("Migrating away from threads has been mentioned here recently for it's 
neat practical usefulness.)

My impression is that regarding the OS-interface of a program that needs 
the said features (multiple "logical threads", performance, latency, 
making use of modern SMP systems, ...), threads are a necessity. But 
programming languages might be able to in many cases hide the dirty 
details from the programmer (e.g. "parallel" loops, see the Delphi Prism 
and/or .NET documentation on these issues.) If FPC could be enhances tn 
that direction it might be a decent improvement.


More information about the Lazarus mailing list