|
Message-Id: <B9275837-6376-4749-8179-E203DC48E230@gmail.com>
Date: Sun, 20 Sep 2015 20:07:28 +0200
From: Julien Ramseier <j.ramseier@...il.com>
To: musl@...ts.openwall.com
Subject: pthread_join stuck in infinite loop
Hello,
pthread_join() never returns when calling it on a detached thread.
I would expect it to return EINVAL instead.
Here’s a small test case:
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
void *world_thd(void *arg) {
sleep(2);
return NULL;
}
int main() {
int ret;
pthread_t thd;
pthread_attr_t attr;
if (pthread_attr_init(&attr))
return 1;
if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))
return 1;
if (pthread_create(&thd, &attr, world_thd, NULL))
return 1;
ret = pthread_join(thd, NULL);
if (ret == EINVAL)
printf("Thread is not joinable\n");
else {
fprintf(stderr, "Failed to join thread: %i\n", ret);
return 1;
}
return 0;
}
--
Julien
Content of type "text/html" skipped
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.