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];
31:   /* init retvals */
32:   for (i=0; i<NTHREADS; i++) retvals[i]=-1;
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]
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:


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.


I believe the reason you can't see the function in the pt.h file is because only the prototypes are stored in the .h file, where as the definition is in the .cpp file.