5
votes

I am porting a windows library to linux. I need to use timed join to wait for the thread to join in a specific timeout.

When I compile the library on Linux I am getting the warning

Implicit declaration of the function - pthread_timedjoin_np

I have included pthread.h and have compiled with -lpthread link. I know that pthread_timedjoin_np is a non-standard GNU function. The function first appeared in glibc in version 2.3.3. and somewhere in BCD v6.

I even checked the Man Page for Linux but got no help. How do I avoid this warning? Any help?

Edit-1: My system is RedHat 5.

1
is this c++ or c? If it is c++, use the new C++0x standard std::thread class and it will be portable without you having to worry about it and remove the c tag. If it is C, please remove the c++ tag. - Jonathan Henson
apologies, it is C! I misused the tag. Let me remove it! - jparthj
did you define #define _GNU_SOURCE - Pradheep
Did you #define _GNU_SOURCE before the #include <pthread.h> ? - Basile Starynkevitch
Sorry, my answer was wrong. Check here, is _GNU_SOURCE defined before any headers are included? You could also add it to the compiler command, -D_GNU_SOURCE - Collin

1 Answers

10
votes

Make sure the #define _GNU_SOURCE is before any of the your headers are included. Macros are set up by <features.h>, which include various parts of the GNU C library. If you've included other headers before you define _GNU_SOURCE, <features.h> will have already been included and will have not seen _GNU_SOURCE.

Even easier, just define it with the compiler adding -D_GNU_SOURCE as a compiler flag.