posix pthreads in c
Posted
by Codenotguru
on Stack Overflow
See other posts from Stack Overflow
or by Codenotguru
Published on 2010-04-13T01:23:58Z
Indexed on
2010/04/13
1:33 UTC
Read the original article
Hit count: 532
threads
Iam new to c programming and needs some help.
long *taskids[NUM_THREADS];
for(t=0; t<NUM_THREADS; t++)
{
taskids[t] = (long *) malloc(sizeof(long));
*taskids[t] = t;
printf("Creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *) taskids[t]);
...
}
This code fragment demonstrates how to pass a simple integer to each thread. The calling thread uses a unique data structure for each thread, insuring that each thread's argument remains intact throughout the program. Iam not able to understand how this is happening can somebody explain it??
© Stack Overflow or respective owner