【发布时间】:2023-03-18 07:50:02
【问题描述】:
我正在努力解决以下问题:
有一个小程序正在尝试移植到调用函数 doWork() 的 OSX(intel) 通过 pthread_create,在函数中,我首先创建一个 long 数组,如下所示:
长 myarray [尺寸]在 OSX 上,对于以下 DIMENSION 值,我得到以下信息:
0->65434 = 很好 65435->67037 = 信号总线 67037+ = SIGSEGV我在这里完全感到困惑,我知道 SIGBUS 通常是由于内存对齐问题,我检查了 sizeof(long) 并且在这个平台上它似乎是 8。有人可以指出我应该在这里阅读的文档的正确方向吗?
这里是来源:
#include pthread.h
#include stdio.h
#define NUM_THREADS 5
#define DIMENSION 12345
void *doStuff(void *threadid)
{
long array[DIMENSION];
pthread_exit(NULL);
}
int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0; t lt NUM_THREADS; t++){
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, doStuff, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);
}
【问题讨论】: