错误很明显。第一个参数应该是一个指针而不是一个整数。
人线程:
int pthread_create(pthread_t *restrict thread,
const pthread_attr_t *restrict attr,
void *(*start_routine)(void*), void *restrict arg);
The pthread_create() function shall create a new thread, with
attributes specified by attr, within a process. If attr is NULL, the
default attributes shall be used. If the attributes specified by attr
are modified later, the thread's attributes shall not be affected. Upon
successful completion, pthread_create() shall store the ID of the cre-
ated thread in the location referenced by thread.
id
在您的 pthread_create 调用之前添加一个&符号之前,请重新阅读最后一句话。EDIT2:您还必须定义id
为 pthread_t。
编辑:
实际上,同一行还有另外两个问题: start_routine 需要是一个接受一个参数而不是两个参数的函数,但最糟糕的是这将是一个fork 炸弹,因为您传递的函数与您调用的函数相同!