<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 10/02/2014 04:23 PM, Xiangrong Fang
wrote:<br>
</div>
<blockquote
cite="mid:CAP93jB0Z-=2=2XVsc1Gf2xiMax1Pip_2wGFScGejn1M0rsnkBA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_default" style="font-family:courier
new,monospace"><br>
</div>
<div class="gmail_extra">
<div class="gmail_quote"><br>
<div><br>
</div>
<div class="gmail_default" style="font-family:'courier
new',monospace">I need my program to work on both Linux
and Windows, can I still use FUTEX? </div>
</div>
</div>
</div>
</blockquote>
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). <br>
<br>
In Linux, the userland Futex stuff is done for you (if possible at
all) in the ppthead library mutex_...() functions. <br>
<br>
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). <br>
<br>
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.<br>
<br>
<blockquote
cite="mid:CAP93jB0Z-=2=2XVsc1Gf2xiMax1Pip_2wGFScGejn1M0rsnkBA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<div class="gmail_default" style="font-family:'courier
new',monospace">For Critical Sections, FPC has the
TCriticalSection object, is there a TMutex object?</div>
</div>
</div>
</div>
</blockquote>
<br>
AFAI understand, "CriticalSection" is the Delphi/fpc name for
"POSIX-Mutex". <br>
<br>
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). <br>
<br>
-Michael<br>
<br>
</body>
</html>