This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcc, pthread on SunOS5.7


On Mon, 30 Jul 2001 15:33:12 +0530, you wrote:

>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 ?

It's a Solaris "feature" - it provides pthread functions' stubs in libc
for programs that don't use multithreading. Don't forget to check what
pthread_create() returns - it does that for a reason. One more thing -
your thread startup functions should really have exactly one void*
parameter and return void* - the way you do it is not guaranteed to work
on any platform.


Cheers!

Dima

>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
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]