【发布时间】:2022-01-07 18:19:42
【问题描述】:
试图通过运行一个简单的程序来查看 pthread 的工作原理,但我在 pthread_create 处遇到分段错误(核心转储)
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
void* testfunc(void* arg) {
while (1) {
printf("testfunc");
}
}
int main(void) {
printf("helo\n");
if (pthread_create(NULL, NULL, &testfunc, NULL) != 0) {
perror("pthread failed to create\n");
}
while (1) {
printf("main function\n");
sleep(1000);
}
return 0;
}
似乎是什么导致了问题?如果这很重要,我在 Ubuntu 20.04 上。
【问题讨论】: