我正在使用 pthreads 进行并行排序。目前,我正在使用 4 个线程,而且我刚刚开始,所以现在没有线程访问相同的全局位置。(我已经全局声明了两个变量,变量是大数组,我确保没有两个线程访问同一个索引。)
在 AASort 内部,我调用了另一个函数。如果我不调用 AASort 函数中的任何函数,则此代码有效。
unsigned int Numbers [N/4] [4];
unsigned int vMergedArray[NumProcs][64][4];
unsigned int v[NumProcs][2][4];
main()
{
/* Initialize array of thread structures */
threads = (pthread_t *) malloc(sizeof(pthread_t) * NumProcs);
assert(threads != NULL);
for(threadId=0; threadId < NumProcs; threadId++) {
ret = pthread_create(&threads[threadId], &attr, AASort, (void*) threadId);
assert(ret == 0);
}
for(threadId=0; threadId < NumProcs; threadId++) {
ret = pthread_join(threads[threadId], NULL);
assert(ret == 0);
}
}