Here is a little C source code using pthread_kill() call:
#include <stdlib.h>
#include <pthread.h>
#include <signal.h>
int main(int argc, char *argv[])
{
pthread_t th = NULL;
pthread_kill(th, 0);
return 0;
}
Gcc compilation produces various results depending on -std argument value (see below). I don't understand these different behaviors. I didn't get interesting informations into man pages except pthread_kill() is POSIX.1-2008 compliant.
Environment: Linux 3.2 64bits. GCC 4.7.2.
gcc main.c -std=c11 -pthread
I get an implicit declaration:
main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
gcc main.c -std=c99 -pthread
Same result as -std=c11:
main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
gcc main.c -std=c90 -pthread
It simply works without any errors/warnings.
Thank you for your feedbacks.
If you use a Posix feature, you need to define an appropriate feature test macro. See man feature_test_macros
or the Posix standard.
If you don't define _POSIX_C_SOURCE
to an appropriate value (depending on the minimum Posix level you require), then interfaces from that and subsequent Posix standards will not be defined by standard library headers.
If you need Posix.1-2008, for example, you need to do this:
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <pthread.h>
#include <signal.h>
int main(int argc, char *argv[])
{
pthread_t th = NULL;
pthread_kill(th, 0);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With