[Linux c/c++] futex

参考:

Pthread locks: Mutex vs Spilocks vs Futex – Deep Code DiveLocking During multi-threading or multi-processing, the biggest challenge is selecting types of locks. When writing C code, one can manually write their own locking mechanism or can use glibc wrappers for Mutex and spinlocks. Mutex vs Spinlocks Mutex are low overhead locking mechanism with the concept of sleeping the process when waiting for the lock.…icon-default.png?t=N7T8https://parthsl.wordpress.com/2019/01/20/pthread-locks-mutex-vs-spilocks-vs-futex/futex(2) - Linux manual pageicon-default.png?t=N7T8https://man7.org/linux/man-pages/man2/futex.2.html

正文:

futex 是用户层面的 锁,使用futex 不会出现用户态到内核态的切换,因此应用程序中要比mutex快一点,如果是驱动程序和内核模块的话,就不要使用futex了,因为驱动和内核模块都运行再内核态,用mutex则更快一点。

你可能感兴趣的:(#,Common/Linux,C/C++,linux,c++,运维)