c++pthreadsmutex

When to use pthread_mutex_t?


Can someone please explain in what scenarios it would be beneficial to use std::mutex vs. pthread_mutex_t. I don't understand why we would ever use pthread_mutex_t.


Solution

  • std::mutex is just a thin wrapper around pthread_mutex on systems supporting pthreads.

    In general, the operations on the std:: thread primitives are quite limited vs the native versions (pthreads or windows threads). If you don't need those features, you should always use the std:: versions, but if you do need the advanced features, then you have no choice but to use the native version.

    native handle() method exists for exactly this reason.