1

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?

Smern
  • 18,746
  • 21
  • 72
  • 90
user2982229
  • 1,395
  • 2
  • 11
  • 13
  • Did you `#include `? – HAL Nov 13 '13 at 13:22
  • Yes included. But not works – user2982229 Nov 13 '13 at 13:23
  • 1
    To start with, you do know that the `_np` ending to the function name means Non Portable? That means it may not exist on all systems. Also, after checking [this FreeBSD manual page](http://www.manualpages.de/FreeBSD/FreeBSD-9.0-RELEASE/man3/pthread_getthreadid_np.3.html) you might need to include ``. Of course, being non-portable the header file might not be correct for Debin Linux. – Some programmer dude Nov 13 '13 at 13:23

1 Answers1

4

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

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644