thr_create Status

thr_create Status

Post by sam p » Thu, 10 Jul 2003 00:21:39



What is wrong in this program? thr_create return -1. This Sun 0s.
Thanks Sam

#define _REENTRANT    /* basic 3-lines for threads */
          #include<stdio.h>
          #include <pthread.h>
          #include <thread.h>

          #define NUM_THREADS 5
          #define SLEEP_TIME 10

          void *sleeping(void *);   /* thread routine */
          int i;
          thread_t tid;      /* array of thread IDs */

int  main(int argc, char *argv[]) {
   int status;
             status=thr_create(NULL, 0, sleeping, (void *)SLEEP_TIME,
0, &tid);
                                  printf("THread
Status=%d,%d\n",status,tid);
                  return (0);
          }  /* main */

          void *
          sleeping(void *arg)
          {
                  int sleep_time = (int)arg;
                  printf("thread %d sleeping %d seconds ...\n",
thr_self(), sleep_time);
                  sleep(sleep_time);
                  printf("\nthread %d awakening\n", thr_self());
                  return (NULL);
          }

 
 
 

thr_create Status

Post by Dragan Cvetkovi » Thu, 10 Jul 2003 00:27:18



> What is wrong in this program? thr_create return -1. This Sun 0s.
> Thanks Sam

How did you link your program? Man page for that function says

     If the application is not linked with the threads library, -1 is
     returned.

HTH, Dragan

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer