Futex based locking mechanism

Dima picture Dima · Sep 24, 2010 · Viewed 9.1k times · Source

Somebody can tell me an example of using locking mechanism based on futex? (for muticore x86 CPU, CentOS)

Answer

Doug picture Doug · Sep 24, 2010

Pthreads' mutexes are implemented using futexes on recent versions of Linux. Pthreads is the standard C threading API on Linux, and is part of the Posix standard, so you can easily port your program to other Unix-like systems. You should avoid using futexes directly unless you have very unusual needs, because they're very hard to use correctly - use pthreads, or a higher-level, language-specific API (which will almost certainly use pthreads itself).