child2函数中pthread_getspecific函数返回空指针
```c
#include <pthread.h>
#include<unistd.h>
#include <sys/types.h>
#include <wait.h>
#include <pthread.h>
#include <stdio.h>
pthread_t ntid1;
pthread_t ntid2;
pthread_key_t p_key;
void *child1(void *args);
void *child2(void *args);
void print_ids(const char *s);
int main()
{
int err1,err2;
pthread_key_create(&p_key,NULL);
err1 = pthread_create(&ntid1, NULL, child1, NULL);
if (err1 != 0)
return 1;
err2 = pthread_create(&ntid2, NULL, child2, NULL);
if (err2 != 0)
return 1;
err1 = pthread_join(ntid1, NULL);
err2 = pthread_join(ntid2, NULL);
pthread_key_delete (p_key);
print_ids("main thread:");
return 0;
}
void* child1(void *args)
{
print_ids("Child1");
return (void*)0;
}
void* child2(void *args)
{
print_ids("Child2");
pthread_setspecific(p_key, args);
int *a = (int*)pthread_getspecific(p_key);
// *a = 619;
printf("Key = %p\n",a);
return (void*)0;
}
void print_ids(const char *s)
{
pid_t pid;
pthread_t tid;
pid = getpid();
tid = pthread_self();
printf("%s pid %lu tid %lu (0x%lx)\n", s, (unsigned long)pid,
(unsigned long)tid, (unsigned long)tid);
}
```