#include <stdlib.h> #include <pthread.h> #include <stdio.h> #include <sched.h> #include<string.h> pthread_key_t key; void destructor(void *data) //如果创建该键时指定了destructor 函数,则该线程终止时,系统会调用destructor 函数,传进的参数是绑定的值。 { if(data != NULL) free(data); printf("thread (%u) do free key ", (unsigned)pthread_self()); } void print_key(void) { char *p; p = (char *)pthread_getspecific(key); printf("(%u) key_value:%s ", (unsigned)pthread_self(), p); } void *thread1(void *arg) { printf("start thread (%u) ", (unsigned)pthread_self()); char * p = malloc(7*sizeof(char)); memset(p, 'a', 6); p[6] = '