已经解决了。感谢各位。原因很简单 After pthread_detach completes, subsequent attempts to perform pthread_join on th will fail. If another thread is already joining the thread at the time pthread_detach is called, pthread_detach does nothing and leaves th in the joinable state.
第一种情况: Linux/Unix的man都会有类似的说明: int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); DESCRIPTION The detachstate attribute controls whether the thread is created in a detached state. If the thread is created detached, then use of the ID of the newly created thread by the pthread_detach() or pthread_join() function is an error 问题比较明显,楼上几位也说清楚了
FC5下man pthread_detach的结果 RETURN VALUE If the call succeeds, pthread_detach() shall return 0; otherwise, an error number shall be returned to indicate the error.