Po pierwsze, czy ten kod powinien wyświetlać 1 i 2 w dowolnej kolejności?
Bo ja już nie wiem. u mnie wyswietla 22222111111
Czy to online compiler nie obsługuje wielu wąktów?.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
void* p (void* l) { // funkcja watku (watek)
int i=0;
while (i<10) {
i++;
printf("%d ",1);
}
return 0;
}
void* q (void* l) { // funkcja watku (watek)
int i=0;
while (i<10) {
i++;
printf("%d ",2);
}
return 0;
}
int main () {
pthread_t w1,w2;
pthread_create(&w1, 0, p,0);
pthread_create(&w2, 0, q,0);
pthread_join(w1,NULL);
pthread_join(w2,NULL);
printf("\nkoniec procesu\n");
return 0;
}