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

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to