[fpc-devel] Threading support and C library under Linux/Unix
Michael Schnell
mschnell at lumino.de
Wed Jun 23 15:09:44 CEST 2010
On 06/23/2010 03:00 PM, Henry Vermaak wrote:
> Why would you want to do that? Just use the futex syscall.
Here you are definitely wrong.
Futex is all about _not_ doing a syscall (i.e. change from user space to
Kernel space and back) but doing the Mutex operation in user space, if
possible (i.e. if not putting a thread to sleep due to Mutex already
taken or to wake a thread if the Mutex is freed and at least one thread
is waiting. As in most cases a Futex (TCtriticalSection) is only locked
for a short time, performance is increased if no syscall needs to be
done if no other thread tries to lock it while it's already taken.
So userspace needs to do some non-trivial stuff without doing the FUTEX
syscall and only do the system call if necessary (see "Futexes are
tricky" I mentioned above).
This includes doing some critical operations in an atomic way (Thread
safe and SMP safe if appropriate).
-Michael
More information about the fpc-devel
mailing list