pthread_create() 返回 11

通过反复的 pthread_create() --->   pthread_exit (0)   一段时间后,会导致pthread_create() 失败,返回11

google后,发现,单纯地调用 pthread_exit (0) 可能导致资源释放不完全或者来不及释放,运行一段时间后,达到系统上限。


解决方法:

1. 主线程这里创建完子线程后,把子线程分离出来,线程运行结束后,让系统自动回收资源

pthread_detach(thread_id)(非阻塞,可立即返回)


2. 或者在线程函数开头,分离自己

pthread_detach(pthread_self())


附上百度百科:pthread_detach()

你可能感兴趣的:(Linux/Linux,C)