看了一圈,外面垃圾博客太多,全是抄袭,没一个提到要点。
#include <stdio.h>
#include <string.h>
#include <pthread.h>
void* print(void* data){
printf("%d\n", (int) (long long) data);
}
int main(){
pthread_t tid[3];
for (int i = 0; i < 3; i++) {
if(pthread_create(&tid[i], NULL, print, (void *)(long long)i) != 0) {
fprintf(stderr, "pthread_create error!\n");
return 0;
}
}
for (int i=0; i<3; i++) {
pthread_join(tid[i], NULL);
}
}