/* 
   This file is part of Practical Distributed Processing
   Copyright (C) 2006-2007 Phillip J. Brooke and Richard F. Paige
*/

#include <stdio.h>
#include <pthread.h>

#define N_THREADS 9

void * threadHello (void *j) {
  printf("Hello world from thread %ld (%d)!\n",
	 (long int) pthread_self(), *(int *)j);
  pthread_exit(NULL);
  return 0; /* Never reach this line. */
}

int main () {
  int i,r;
  pthread_t t;
  int d[N_THREADS];

  for (i=0; i<N_THREADS; i++) {
    printf("Creating thread %d...\n", i);
    d[i] = 2*i;
    r = pthread_create(&t, NULL, threadHello, (void *) &d[i]);
  }
  printf("Main function (nearly) done.\n");
  /* Why do we have main() call pthread_exit? */
  pthread_exit(NULL);
  return 0; /* Never reach this line. */
}
