multithreading - not understanding a part of code -
hi not understanding part of code in threads program , code
int niza[1000]; pthread_t threads[6]; void *popolni(void* n) { int counter=*(int *)n; for(int i=0;i<n;i++) niza[i]=rand()%counter; pthread_exit(null); } void *promeni(void* id) { int threadid=*(int *)id,dolzina=strlen(niza); int del=round(dolzina/4); for(int i=(id-1)*del;i<id*del;i++) niza[i]+=niza[i]/2; pthread_exit(null); } void *pecati(void* n) { int counter=*(int *)n; for(int i=0;i<counter;i++) printf("%d ",niza[i]); pthread_exit(null); } int main(int argc, char* argv[]) { srand(time(null)); int n; scanf("%d",&n); pthread_create(&threads[0],null,popolni,(void *)&n); pthread_join(threads[0],&status); for(int i=1;i<5;i++) pthread_create(&threads[i],null,promeni,(void *)&i); for(int i=1;i<5;i++) pthread_join(threads[i],&status); pthread_create(&threads[5],null,pecati,(void *)&n); pthread_join(threads[5],&status); return 0; }`
the part don't understand this
for(int i=(id-1)*del;i<id*del;i++) niza[i]+=niza[i]/2;
the first thread has fill array , second 4 threads have split on 4 parts , fill array . me?
Comments
Post a Comment