gcc, pthread on SunOS5.7

Anand Padhye anand.padhye@wipro.com
Mon Jul 30 03:00:00 GMT 2001


Hello!
I am using simple threads in my code (using gcc on SunOS 5.7). Works fine if
linked using -lpthread. If I do not use -lpthread, it still gives no error,
creates a.out but does not run properly. Whay does gcc not give linking
error on SunOS5.7 if -lpthread is not given ? It gives a linking error on
Linux if -lpthread is not given.

Can someone help ?

Here is the code ---

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

int f1()
{
   int x1 = 0;
   while (1)
   {
      x1++;
      printf("f1() - x1 = %d\n", x1);
      sleep(3);
   }
}

int f2()
{
   int x2 = 0;
   while (1)
   {
      x2++;
      printf("\t\t\t f2() - x2 = %d\n", x2);
      sleep(3);
   }
}

int main()
{
   pthread_t t1, t2;

   pthread_create(&t1, NULL, (void*)f1, NULL);
   pthread_create(&t2, NULL, (void*)f2, NULL);

   while(1)
   {
      printf("main() - still running\n");
      sleep(5);
   }

   return 0;
}


Regards,
Anand




More information about the Libc-alpha mailing list