[fpc-pascal] Re: Multi-threaded project with few locks (no Thread.waitfor). Memory consumption keeps increasing on Ubuntu 10.10 x64
Vinzent Höfler
JeLlyFish.software at gmx.net
Sat Oct 16 16:57:27 CEST 2010
On Sat, 16 Oct 2010 10:45:49 +0200, Luca Olivetti <luca at ventoso.org> wrote:
> Al 15/10/10 22:31, En/na Vinzent Höfler ha escrit:
>
>> - FreeOnTerminate should be gone, (meaning no way to actively call
>> TThread.Destroy from another thread, a thread gets destroyed
>> automatically when it leaves its execute method)
>
> I don't agree, the creator of the thread should be able to see what's
> happening to it (i.e. keeping a reference to the thread without risking
> a SIGSEV because the thread has terminated).
Well, the usual implementation of an externally called "Destroy" is
- first a call to the Terminate method
- then a WaitFor()
Unfortunately WaitFor maps quite directly to pthread_join() while a
self-destruction is done by pthread_exit(). You can NOT call both
without triggering "undefined behaviour" which - beginning with some
2.6 kernel - was a segmentation fault already, and you can not call
pthread_join() from the same thread, this would deadlock.
There are several solutions to the problem, each one with its
own drawbacks. I would like to avoid additional synchronisation
requirements as well as introducing new race conditions.
With these implementation issues, implementing a race condition free
WaitFor is already hard enough, but allowing Destroy to be called
externally adds more issues than it can possibly solve.
Vinzent.
More information about the fpc-pascal
mailing list