gpt4 book ai didi

c cygwin- abored(核心已转储)

转载 作者:行者123 更新时间:2023-11-30 14:23:27 25 4
gpt4 key购买 nike

我已经尝试了很长时间,但无法弄清楚这个'core dumped'来自哪里。我正在 cygwin 上使用 c。注释掉线程可以解决问题,但注释掉线程中的整个代码没有任何作用。这可能与线程的调用有关吗?它似乎正在发挥作用,然后突然发生了这种情况。我已经删除了大部分代码,这就是剩下的-

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <pthread.h>
#include <string.h>


typedef enum {true=1, false=0} bool;

void *piThread(void *arg);
int finished;

int main(int argc, char *argv[])
{
int i;
int threads;
bool display = false;
long double pI = 0.0;
void *status = malloc(sizeof(int));
pthread_t thread_id[threads];

if(argc < 2) {printf("not enough arguments"); exit(1);
}else threads = atoi(argv[1]);

if(argc == 3)
if (strcmp(argv[2], "b") == 0)
display = true;

for(i=0; i<threads; i++)
{
pthread_create(&thread_id[i], NULL, piThread, NULL);
pthread_join(thread_id[i], &status);
printf("pi: %Lf\n", pI);
}
return 0;
}

void *piThread(void *arg)
{
int number = 0;
number = 74;
pthread_exit((void*)number);
}

这会导致错误中止。

Stack trace:
Frame Function Args
0028A6A4 76821184 (000000D0, 0000EA60, 00000000, 0028A7D8)
0028A6B8 76821138 (000000D0, 0000EA60, 000000A4, 0028A7B4)
0028A7D8 610DBE29 (00000000, FFFFFFFE, 77403B23, 77403B4E)
0028A8C8 610D915E (00000000, 0028A918, 00000001, 00000000)
0028A928 610D962E (76D709CD, 7427AED9, 00000003, 00000006)
0028A9D8 610D9780 (000011E8, 00000006, 002B002B, 800483D8)
0028A9F8 610D97AC (00000006, 0028CE80, FFFDE000, 00000000)
0028AA28 610D9A85 (000000D0, 0028ABF0, 0028AA58, 610FA223)
End of stack trace

我不知道出了什么问题!命令行是-海湾合作委员会pi.exe 100任何高于 26 的组合都会导致此故障。感谢您的任何见解

最佳答案

您在定义“线程”之前分配 thread_id。这至少应该解决这个问题。

if(argc < 2) {printf("not enough arguments"); exit(1);
}else threads = atoi(argv[1]);
pthread_t thread_id[threads];

关于c cygwin- abored(核心已转储),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12858784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com