Linux man page :
When a joinable thread terminates, its memory resources (thread descriptor and stack) are not deallocated until another thread performs pthread_join on it. Therefore, pthread_join must be called once for each joinable thread created to avoid memory leaks.
线程会占用资源,如果不回收的话会导致内存泄露。
//自己结束时释放
pthread_detach(pthread_self());
//或者创建线程前设置 PTHREAD_CREATE_DETACHED 属性
pthread_attr_t attr;
pthread_t thread;
pthread_attr_init (&attr);
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
pthread_create (&thread, &attr, &thread_function, NULL);
pthread_attr_destroy (&attr);
转载于:https://blog.51cto.com/which/1372182