Witam, czy mógłby ktoś mi wytłumaczyć działanie programu poniżej a mianowicie czemu najpierw wypisuje się liczba 2 a nie 1 (podejrzewam że jest to sprawka pthread_join ale jakoś nie mogę ogarnąć ich działania w tym programie) a także czemu ten program jest współbieżny?
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
void* p (void* l)
{
int i = 0;
for(i;i<10;i++)
{
printf("%d ",1);
fflush(stdout);
usleep(500000);
}
return 0;
}
void* q (void* l)
{
int i = 0;
for(i;i<10;i++)
{
printf("%d ",2);
fflush(stdout);
usleep(500000);
}
return 0;
}
int main(){
pthread_t w1=0, w2=0;
pthread_create(&w1, 0, p, 0);
pthread_create(&w2, 0, q, 0);
pthread_join(w1, NULL);
pthread_join(w2, NULL);
printf("koniec");
return 0;
}