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