[Lazarus] Threads in Lazarus code base

Mattias Gaertner nc-gaertnma at netcologne.de
Wed Sep 15 13:25:50 CEST 2010


On Wed, 15 Sep 2010 13:05:40 +0200
Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:

> On 15 September 2010 12:38, Juha Manninen (gmail) wrote:
> > On Wednesday 15 September 2010 13:32:20 Michael Schnell wrote:
> >>   Maybe you could start an external process for this ....
> >
> > ... and pass the data with temporary text files?
> > Why would I do that? A thread is lighter, it can see the variables I already
> > defined, it is easier to synchronize (WaitFor in this case)...
> >
> > What is wrong with threads?
> 
> Juha, I fully agree with you. I also can't believe Lazarus is single
> threaded. I know of *many* areas where multiple threads could make
> Lazarus a lot more "snappy"!

True. And I have already plans to use some threads.

 
> The questions should rather be "why must we not use threads"? With all
> the the multi-core CPU's out there, and all the background tasks the
> IDE could do - staying single thread is rather daft.

Threads have several disadvantages: 
*They are harder to debug, 
*it is harder to follow the program flow, 
*you have to program carefully to avoid dead lock and non exclusive
access, which is especially hard where design time packages extends
the code base,
*many IDE parts will become slower (once you start a thread the RTL
uses critical sections and especially string handling become much
slower).

 
> I use multiple threads all the time in our software. Yes it's an
> "advanced" feature of the language, so you need to know what you are
> doing. But I thought a IDE would qualify as an "advanced application"
> - after all, it's slightly more code than a "hello world" app. :-)  I
> would expect the developers that work on the IDE, to also be "advanced
> developers" with a bit more know-how than newbies to the Object Pascal
> language.

Yes, and there is a golden rule:
Before doing threads, always try first to do it good single threaded.
Many things can be done on idle. In fact the IDE does many things on
idle, for example the code explorer, the fpdoc editor, the code
hints, the code browser. These work in small steps.

Juha: scanning unit paths can be done on idle too. Of course when
searching a network the waits can be quite long, and then another
thread/process is needed.

Mattias




More information about the Lazarus mailing list