Witam, mam oto taki kod:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#define MAXL 10
int l_losowe [MAXL];
long licznik = 0;
void* p(void* l)
{
srand(time(NULL));
long n = (long)l;
int los = rand()%10;
l_losowe[n]=los;
printf("watek nr %ld, liczba %d\n",n,los);
return 0;
}
int main()
{
pthread_t w[MAXL];
for(licznik = 0;licznik<MAXL;licznik++)
{
pthread_create(&w,0,p,(void*)licznik);
}
for(licznik = 0;licznik<MAXL;licznik++)
{
pthread_join(w[licznik],0);
}
int j=0,x=0;
for(j;j<MAXL;j++)
{
x+=l_losowe[j];
}
x=x/licznik;
printf("średnia: %d",x);
return 0;
}
Wypisuje on caly czas ta sama liczbę wylosowaną. Co mogę dodać/przestawić by się tak nie działo?