[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
Fri Oct 15 22:31:00 CEST 2010


On Fri, 15 Oct 2010 22:13:36 +0200, Sven Barth  
<pascaldragon at googlemail.com> wrote:

> I'm curious. How should this FPThread class look like? You saw flaws in  
> Delphi's API so what would you do better?

Hmm. Actually, I did not think too hard about it yet.

So for a quick brainstorming approach:

- Suspend/Resume should be gone (you can't guarantee it to work,
   so there's no point in doing it at all)
- 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)
   (IIRC FreeOnTerminate was even set to False by the default
    constructor, so you had the choice of either using the default
    or introducing a race condition by setting it after the
    "inherited Create" - which starts the execute.)

That should solve most problems. It does not solve the problem that
object validity errors occur when the execute method is compiled
with range checks on and the VMT (I believe it is) is checked,
because this is not done before the constructor has been finished,
but at that point the Execute method may already be running.

So I suppose, a "Start" method must be introduced which must be
called after the creation of the thread (which would be real
nasty), and that still does not solve the problem with the missing
ThreadId which means, the Execute method must be wrapped to call
CurrentThread before the actual overriden method is called...

> Note: I'm not implying that Delphi's API is good... as a Delphi/FPC user  
> I don't know of another Object Oriented Pascal alternative and thus  
> would like to know what you'd improve.

The Delphi-API simply is too Windows-centric, that's all. I wouldn't
actually blame it on Borland either, but simulating Windows semantics
on systems other than Windows is not likely to lead to very efficient
designs.


Vinzent.

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/



More information about the fpc-pascal mailing list