私はCでpthreadを探しています。だから私は新しいです。私はpthreadコードの中でポインタの構文と役割を学びたいと思っています。コードによると私の過ちは何ですか?私は何をしたのかわかりません。pthreadライブラリの基本的な例が正しく動作しません
戻り値を確認しようとしているときpthread_create()
私は間違った/ランダムな値を取得しています。
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int *f_1,*f_2,*f_3,*f_4;
void p1(void *a);
void p2(void *a);
void p3(void *a);
void p4(void *a);
int main(void){
pthread_t thread_1, thread_2, thread_3, thread_4;
int *x=1,*y=2,*z=3,*w=4;
f_1=pthread_create(&thread_1, NULL, p1,(void *)x);
f_2=pthread_create(&thread_2, NULL, p2,(void *) y);
f_3=pthread_create(&thread_3, NULL, p1,(void *) z);
f_4=pthread_create(&thread_4, NULL, p1,(void *) w);
pthread_join(thread_1,NULL);
pthread_join(thread_2,NULL);
pthread_join(thread_3,NULL);
pthread_join(thread_4,NULL);
printf("Hi! From %d. thread!",f_1);
printf("Hi! From %d. thread!",f_2);
printf("Hi! From %d. thread!",f_3);
printf("Hi! From %d. thread!",f_4);
return 0;
}
void p1(void *a){
f_1=(int *)a;
}
void p2(void *a){
f_2=(int *)a;
}
void p3(void *a){
f_3=(int *)a;
}
void p4(void *a){
f_4=(int *)a;
}
'明らかに、私がしたこと。 "...質問:あなたはどうしたのですか? –
少なくとも、あなたがしようとしていたことや、このコードで何が問題になっているのか説明できますか? –
いくつかのウェブサイトからはコンパイルされていませんでした。 – QatarNotAlone