static int nthreads = 4;
+static pthread_key_t thrnumkey;
+
static void
threxit(void *arg)
{
}
pthread_mutex_unlock(&mtx);
+ if (pthread_getspecific(thrnumkey) != arg) {
+ printf("ERROR: specificdata fail");
+ abort();
+ }
+
printf("thread %p EXIT %d\n", arg, nthreads);
}
{
printf("thread %p\n", arg);
+ pthread_setspecific(thrnumkey, arg);
pthread_mutex_lock(&mtx);
printf("got lock %p\n", arg);
{
printf("thread %p\n", arg);
+ pthread_setspecific(thrnumkey, arg);
pthread_mutex_lock(&mtx);
while (!predicate) {
printf("no good, need to wait %p\n", arg);
{
printf("thread %p\n", arg);
+ pthread_setspecific(thrnumkey, arg);
pthread_mutex_lock(&mtx);
predicate = 1;
printf("rise and shine %p!\n", arg);
struct timespec ts;
pthread_t pt;
+ pthread_key_create(&thrnumkey, NULL);
+
pthread_mutex_init(&mtx, NULL);
pthread_cond_init(&cv, NULL);
pthread_cond_init(&cv2, NULL);