Overhead of pthread mutexes?

前端 未结 9 1845
旧时难觅i
旧时难觅i 2020-12-13 18:46

I\'m trying to make a C++ API (for Linux and Solaris) thread-safe, so that its functions can be called from different threads without breaking internal data structures. In m

9条回答
  •  独厮守ぢ
    2020-12-13 19:09

    "A mutex requires an OS context switch. That is fairly expensive. "

    • This is not true on Linux, where mutexes are implemented using something called futex'es. Acquiring an uncontested (i.e., not already locked) mutex is, as cmeerw points out, a matter of a few simple instructions, and is typically in the area of 25 nanoseconds w/current hardware.

    For more info: Futex

    Numbers everybody should know

提交回复
热议问题