#include <pthread.h>
void thread_routine(void*)
{
sleep(5);
pthread_detach(pthread_self());
sleep(5);
}
int main()
{
pthread_t t;
pthread_create(&t, 0, thread_routine, 0);
pthread_join(t);
}
将pthread_join(t);
在pthread_detach(pthread_self());
成功后立即返回?如果被等待的线程自行分离,该怎么办?
我的猜测,就像在调用pthread_join之前线程被分离一样:UB。 – Deduplicator 2014-12-03 03:19:05