2
运行此程序时出现分段错误。使用gdb,我确认它在拨打pthread_create
。创建线程时出现分段错误
#include <stdio.h>
#include <pthread.h>
struct point {
int x;
int y;
char name;
};
void *start (void * P) {
while (1) {
}
}
main() {
struct point P;
P.name = 'P';
P.x = 1;
P.y = 2;
pthread_t *tid;
pthread_create (tid, NULL, (void *) start, (void *) &P);
while (1) {
}
}
有人可以帮忙吗?
哦,是的!它现在有效。但是,为什么它的工作,而不是一个结构指针P,我传递一个整数指针? –
@SagarJha未定义的行为并不意味着每次都无法工作。它偶尔会发生作用,但你不能依赖它。 –
因为你在开始时忽略了P,所以它的值是不相关的,从来没有使用过 –