[fpc-devel] Fpsigprocmask

Michael Schnell mschnell at lumino.de
Tue Jan 26 12:39:34 CET 2010

On 01/25/2010 08:46 PM, Martin Schreiber wrote:
> Do you think a futex is cheaper than an interlockedincrement()?

Sorry, I forgot to answer to your question in the first mail.

Of course any FUTEX implementation needs to use something like
interlockedincrement() to do the user space implementation.

But FUTEX is a _very_ complicated and malicious issue. I do know that
there were several generations of Futex implementations until a really
working one was released (the first one was done by Linus Torwalds
himself ... and proved to be not working correctly). AFAIK: The main
problems arise when a mutex is freed and a single waiting threads is to
be freed and given the mutex while multiple other threads are supposed
to go on waiting.

So _if_ the implementation with interlockedincrement and sema in fact
works in the code you use it for, I believe it only works in certain
cases (perhaps exactly those your code produces), but will fail in others.

I only came across this issue, as your "sema" implementation uses the
"discouraged" old libc unit, and while porting your code I of course
wanted to do that along the lines the FPC developers suggest. But your
semty Type seems to be quite different from what is provided in the RTL
e.g. with syncobjs.

Maybe we can work  together to improve your NoGUIApplication class: (1)
not using that libc unit and (2) use Futex. I'll come back with what I find.

Could you please explain what exactly  the interlockedincrement in
sys_semdestroy is used for and what sys_semdestroy is necessary for with
NoGUIApplication. Perhaps you could suggest  an idea how to implement
your sys_sema...() functions using syncobj (or whatever) instead of
direct libc calls.


More information about the fpc-devel mailing list