/* phello.c
   Copyright (c) 1996 Jered Floyd

   My first threaded program. Yeah! 3/18/95
 */

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

#define OK      0
#define NOTOK  -1

const char buf[] = "Hello, World!\n";
int fd = 1;

/*
 * usage();
 */
void usage(void)
{
  printf("phello [--version | --mail]\n");
  errno = 0;
}

void* new_thread(void* arg)
{
  write(fd, buf + (long) arg, 1);
  pthread_exit(NULL);
}

main(int argc, char **argv)
{
  pthread_t thread;
  int count = 14;
  int eof = 0;
  long i;

  pthread_init();

  for (i = 0; i < count; i++) {
    if (pthread_create(&thread, NULL, new_thread, (void*)i)) {
      printf("error creating new thread %d\n", i);
    }
  }
  pthread_exit(NULL);
  fprintf(stderr, "pthread_exit returned\n");
  exit(1);
}
