Hi,
The problem I am facing is that I don't understand the code mentioned in the following:
25: /******** this is the main thread's code */
26: int main(int argc, char *argv[])
27: {
28: int i;
29: int retvals[NTHREADS];
30:
31: /* init retvals */
32: for (i=0; i<NTHREADS; i++) retvals[i]=-1;
33:
34: /* do it */
35: [B]pt_fork(NTHREADS, /* # of threads to create */
36: hola, /* routine they execute */
37: retvals, /* a piece of global data they all share */
38: NULL); /* ignore exit codes */[/B]
39:
40: /* check return values */
41: for (i=0; i<NTHREADS; i++)
42: if (retvals[i]!=i) {
43: fprintf(stderr,"thread %d didn't return a value\n",i);
44: exit(1);
45: }
46: return(0);
47: }
The pt_fork's source is given as:
[http://math.arizona.edu/~swig/documentation/pthreads/pt.h]
extern void _pt_fork(int nthreads,
pt_startroutine_t start,
pt_addr_t arg,
pt_addr_t *exitcodes);
#define pt_fork(nt,start,arg,codes) \
_pt_fork(nt,(pt_startroutine_t) start, \
(pt_addr_t) arg,(pt_addr_t *) codes)
As can be seen from the "pt.h", the function body of _pt_fork is empty. I am not convinced where the pthread_create is being called from within _pt_fork. Ultimately, threads must be created by calling pthread_create. But the main function above calls the pt_fork(), and the call to pthread_create seems to go into a black hole defined by pt_fork.
Thanks.