#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