从POSIX线程的pthread_create的所有参数都非常直截了当,除了pthread_attr_t。什么是pthread_attr_t的,怎么样,当它应该是不被NULL初始化?当pthread_attr_t不是NULL?
我通过了Linux man page。我发现的描述有关pthread_attr_t是:
语法:
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void*),void *arg);
说明:
The attr argument points to a pthread_attr_t structure whose contents are used at thread creation time to determine attributes for the new thread; this structure is initialized using pthread_attr_init(3) and related functions. If attr is NULL, then the thread is created with default attributes.
这是非常不清楚。我还在互联网上搜索了一遍,也没有找到任何明确的解释。所以,当pthread_attr_t不是NULL?
有人可以请说一说吗?所有评论和反馈都非常感谢。
非常感谢你的启发性答案。你提到:“创建一个分离(不可连接)的线程”...然后我遵循你的建议,并找到这个例子:http://stackoverflow.com/questions/6202762/pthread-create-as-detach ed和还发现更多的为什么或何时有线程分离:http://stackoverflow.com/questions/3756882/detached-vs-joinable-posix-threads。谢谢! –