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?

3

1 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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.