Я пытаюсь сделать простую программу с помощью pthreads, хочу сделать 6 потоков и передать индекс всем из них. вот код:Программа pthreads не очень хорошо работает
#include <pthread.h>
#include <stdio.h>
#define num_students 6
void thread_starter();
int main() {
pthread_t thread1[num_students];
int i = 0;
for(i = 0; i<num_students; i++) {
int q = i;
pthread_create(&thread1[i], NULL, (void *) &thread_starter, (void *)&q);
}
sleep(1);
}
void thread_starter(void* a) {
printf("Thread %i \n", *((int*)a));
}
И выход:
Thread 2
Thread 3
Thread 2
Thread 4
Thread 5
Thread 5
почему они commmon имена? что не так?
Благодаря
aaah спасибо, да, имеет смысл, спасибо :)) –