This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: gcc, pthread on SunOS5.7
- To: "Anand Padhye" <anand dot padhye at wipro dot com>
- Subject: Re: gcc, pthread on SunOS5.7
- From: dvv at egcs dot dvv dot ru (Dima Volodin)
- Date: Mon, 30 Jul 2001 14:08:48 GMT
- Cc: <gcc at gcc dot gnu dot org>, <libc-alpha at sourceware dot cygnus dot com>, <linux-gcc at vger dot kernel dot org>
- Organization: Huh?
- References: <000b01c118de$d7f5c8a0$520b6f0a@anand>
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
>
>