[fpc-pascal] Is TFPList thread safe?
Michael Schnell
mschnell at lumino.de
Mon Oct 6 11:39:46 CEST 2014
On 10/02/2014 04:23 PM, Xiangrong Fang wrote:
>
>
>
> I need my program to work on both Linux and Windows, can I still use
> FUTEX?
I did not recommend to use FUTEX yourself. Futex is a rather complicated
thingy that needs ASM for a combination of atomic user land operations
and system calls (that are done if necessary).
In Linux, the userland Futex stuff is done for you (if possible at all)
in the ppthead library mutex_...() functions.
I am not sure that the fpc RTL in fact uses the pthread (standard
C-language) library for TCrtitical section, but this would make sense,
as in that library the dirty stuff is handled. (E.g. _not_ using FUTEX,
but plain old MUTEX in case the arch does not provide FUTEX - there are
several archs that don't provide FUTEX - AFAIK, X86, X86/64 and ARM32
do provide it).
Regarding Windows, I have not much knowledge about such low-level stuff.
AFAIK, all Windows system calls are done via DLLs, and so always some
Microsoft code is executed in Userland, anyway. Hence it is well
possible that the Window "MUTEX" System-DLL-Call (like the pthreadlib so
in Linux) automatically does a FUTEX-alike thingy.
> For Critical Sections, FPC has the TCriticalSection object, is there a
> TMutex object?
AFAI understand, "CriticalSection" is the Delphi/fpc name for
"POSIX-Mutex".
Of course you can do you own low-level implementation of a MUTEX/FUTEX
Sync-Object. Doing that directly in ASM might be slightly faster than
calling the C-phtreadlib. But this definitively is hard stuff.
(Unfortunately Linux does not - and supposedly will not very soon
support the rather new "vdso" concept - a kind of user-land system calls
- for FUTEX/MUTEX).
-Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20141006/9698814d/attachment.html>
More information about the fpc-pascal
mailing list