I am using Debian stable. I was coding a multithreaded application in C++ and using g++ compiler and -lpthread argument to compile.
But the function pthread_getthreadid_np() not works:
error: ‘pthread_getthreadid_np’ was not declared in this scope
what is causing this error?
31 Answer
_np means "not portable" (or "not Posix"), meaning it's not available on all platforms. This function seems to be specific to BSD, to get a platform-specific integer ID for the calling thread. It doesn't exist on Linux.
Depending on what it's used for, you may or may not be able to use the pthread_t handle returned by the portable pthread_self function (which is an integer type on Linux), or the numeric thread ID returned by the Linux-specific gettid system call. Alternatively, rethink whatever you're doing so you don't need to deal with thread identities.