[Lazarus] Threads in Lazarus code base
Juha Manninen (gmail)
juha.manninen62 at gmail.com
Wed Sep 15 14:05:33 CEST 2010
On Wednesday 15 September 2010 14:29:15 Michael Van Canneyt wrote:
> Most programs and algorithms are not thread safe.
> So if you start introducing threads, that means that there are a lot more
> things that can start going wrong, introducing an extra maintenance
> burden on the Lazarus team.
> I'm not saying that your code *will* cause things to go wrong;
> But once the door is open...
Yes, I understand the problems that extensive use of threads can cause.
However in this case it is safe because the thread is running in parallel with
a modal dialog and the rest of Lazarus is doing nothing. Also, the thread can
freely access the variables it needs, there is no interaction with the dialog.
It only runs in parallel with it. The thread does not continue after the
dialog closes (hence WaitFor).
This kind of usage improves the user experience even with 1 CPU core.
Another good use for threads is splitting a loop into parallel sections.
I actually used the MultiThreadProcs package. It is a cool piece of SW.
This improves performance with many CPU cores.
Totally banning threads is not right, IMO. Of course one has to be careful
with them, but that's what programming is about. It is not for sloppy people.
More information about the Lazarus