私はpthreadsプログラムをcで実行できません。以下のプログラムで何が問題なのか教えてください。私はエラーも予想される出力も得られません。pthreadプログラムの後に何が問題になっていますか?
void *worker(void * arg)
{
int i;
int *id=(int *)arg;
printf("Thread %d starts\n", *id);
}
void main(int argc, char **argv)
{
int thrd_no,i,*thrd_id,rank=0;
void *exit_status;
pthread_t *threads;
thrd_no=atoi(argv[1]-1);
thrd_id= malloc(sizeof(int)*(thrd_no));
threads=malloc(sizeof(pthread_t)*(thrd_no));
for(i=0;i<thrd_no;i++)
{
rank=i+1;
thrd_id[i]=pthread_create(&threads[i], NULL, worker, &rank);
}
for(i=0;i<thrd_no;i++)
{
pthread_join(threads[i], &exit_status);
}
}
まあ、あなたのプログラムは、行数と同じ数の警告を作成します。いくつかのインクルードを追加し、警告を整理することを検討してください。コンパイラは厄介な驚きについてあなたに話すことにかなり優れており、警告に注意する必要があります。 – zmccord