carb::this_thread::getId
Defined in carb/thread/Util.h
-
inline thread::ThreadId carb::this_thread::getId()
Retrieve the thread ID for the current thread.
Note
(Linux) This function returns the thread ID which is different than
pthread_self()
. This thread ID can be found withsyscall(SYS_gettid)
, but this can be very slow as it is a syscall. To be more performant, Carbonite attempts to read the value from within the opaquepthread_t
, but there is no guarantee that GLIBC will keep this value in the same location permanently. If the value cannot be read frompthread_t
, it will fall back to using the slower syscall. This value is not stored in athread_local
because older versions of GLIBC (such as 2.17 which is used by Centos7) require a lock that is also required for loading shared libraries, which can cause a deadlock.- Returns
The thread ID for the current thread.