linuxmultithreadingc++11pthreads

C++11: Is std::thread on linux depending on pthread library?


I read that pthread is C library and is not compatible with C++ object model, especially when talking about exception handling.

So I wish to know on linux system, how gcc/clang implements std::thread, is it calling some linux native functions/kernel apis or something?

Also, how is std::thread_local implemented, related with __thread?


Solution

  • Use ldd myExecutable on compiler output to find out.

    Both libstdc++ and libc++ apparently use pthreads, but they are not required to do that. Evidence of it can be found in native_handle methods documentation here and here. The documents say:

    Accesses the native handle of *this.

    The meaning and the type of the result of this function is implementation-defined. On a POSIX system, this may be a value of type pthread_cond_t*. On a Windows system, this may be a PCONDITION_VARIABLE.

    and

    Returns the implementation defined underlying thread handle.