     #define _REENTRANT    /* basic 3-lines for threads */
     #include <pthread.h>
     #include <thread.h>
     #include "Lib.c"      /* Timing utilities included */

     #define NUM_THREADS 2000 

     void *sleeping(void *);   /* thread routine */

     int
     main(int argc, char *argv[])
     {
     int i;
     thread_t tid[NUM_THREADS];      /* array of thread IDs */
     myTime mytime;

             if (argc == 1)  {
                     printf("\n\no Use 0 as arg1 to use pthread_create()\n");
                     printf("o Use 1 as arg1 to use thr_create()\n");
                     printf("o Use 2 as arg1 to set THR_BOUND and THR_NEW_LWP flags in thr_create()\n\n\n");
                     return (1);
             }

	     /* Starting Timer[0] */
	     BeginTiming(0);

             switch (*argv[1])  {
             case '0':  /* POSIX */
                     for ( i = 0; i < NUM_THREADS; i++)
                             pthread_create(&tid[i], NULL, sleeping, (void *)NULL);
                     for ( i = 0; i < NUM_THREADS; i++)
                             pthread_join(tid[i], NULL);
                     break;

             case '1':  /* Solaris */
                     for ( i = 0; i < NUM_THREADS; i++)
                             thr_create(NULL, 0, sleeping, (void *)NULL, 0,
                                 &tid[i]);
                     while (thr_join(NULL, NULL, NULL) == 0);
                     break;

	     case '2':  /* Set THR_BOUND and THR_NEW_LWP when calling thr_create() */
                     for ( i = 0; i < NUM_THREADS; i++)
                             thr_create(NULL, 0, sleeping, (void *)NULL, THR_BOUND | THR_NEW_LWP,
                                 &tid[i]);
                     while (thr_join(NULL, NULL, NULL) == 0);
		     break;

	     case '3':  /* Set THR_BOUND when calling thr_create() */
                     for ( i = 0; i < NUM_THREADS; i++)
                             thr_create(NULL, 0, sleeping, (void *)NULL, THR_BOUND,
                                 &tid[i]);
                     while (thr_join(NULL, NULL, NULL) == 0);
             }  /* switch */

	     mytime = EndTiming(0);
	     printf("\n Running time accounted as follows: ");
	     printf("\n   o System Level running time of thread creation is %lf", mytime.stime);
	     printf("\n   o User Level running time of thread creation is %lf", mytime.utime);

             printf("\n\nmain() reporting that all %d threads have terminated\n\n", NUM_THREADS);

             return (0);
     }  /* main */

     void *
     sleeping(void *arg)
     {
	     return(NULL);
     }

