任何人都可以逐步解释为什么在调用 pthread_create
时出现这样的参数(NULL
指针),如下所示:
pthread_create(&id_thread1,NULL,thread1,NULL);
导致thread1
的默认属性?
我知道 pthread.h
文件是这里的关键因素。
但不幸的是我不明白为什么;该代码对我来说太复杂了。
提前致谢!
最佳答案
pthread_create
的签名是:
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
第二个参数是一个pthread_attr_t*
指针。这允许您设置 various attributes of the thread ,例如调度策略或线程堆栈大小,使用 pthread_attr_t 对象。如果 attr
为 NULL
则使用默认属性。
第四个参数只是一个void*
指针,它可以指向线程开始时要传递给start_routine
的任意用户数据。如果 arg
为 NULL
,则传递空指针。
关于c - 默认属性和 pthread_create() POSIX C linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14403101/