1
これは私のコードの略語です。私は "initializeGrid()"が適切に動作することを明確にする必要があります。簡潔にするために、私はそれを含めませんでした。 argsの値を表示するのに "threadFunction()"を取得しようとしていますが、動作しません。助けてください!スレッドが正しく生成されないのはなぜですか? C
#include <pthread.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
int gridSize = 12;
typedef struct threadParameter {
float * grid;
int top;
int bot;
}threadParameter;
void* threadFunction(void* args) {
threadParameter *param = (threadParameter*) args;
printf("%d, %d", param->bot, param->top);
return 0;
}
int main(int argc, char *argv[]) {
int numProcs = 4;
pthread_t * threadsArr = malloc(numProcs * sizeof(pthread_t));
float mainGrid[gridSize][gridSize];
memset(mainGrid, 0, gridSize*gridSize * sizeof(float));
initializeGrid(1.0, 2.0, 3.0, 4.0, mainGrid);
threadParameter t = {&mainGrid[0][0], 0, gridSize};
int ret = pthread_create(&threadsArr[0], 0, threadFunction, (void*)&t);
}
、非常に多くの@Andrewヘンレをありがとう!それはまさに問題です。迅速で詳細な対応をありがとう! – SupposedlySleeping
この問題を解決する別の方法は、 'main'からの暗黙的な戻りの代わりに' pthread_exit'を行うことです。これにより、プロセスが生き残り、他のすべてのスレッドが選択したとおりに終了します。 –