[668] in Pthreads mailing list archive

home help back first fref pref prev next nref lref last post

Re: pthreads problem on AIX 4.1

daemon@ATHENA.MIT.EDU (yoda@heidelbg.ibm.com)
Thu Jun 19 06:21:46 1997

From: yoda@heidelbg.ibm.com
To: Nick.Godbey@es.atl.sita.int (Nick Godbey)
Date: Thu, 19 Jun 1997 11:37:05 +0200 (MSZ)
Cc: pthreads@MIT.EDU
In-Reply-To: <199706182143.RAA14213@sunshine.es.atl.sita.int> from "Nick Godbey" at Jun 18, 97 05:43:39 pm

I can't reproduce the error message.

First, you might want to modify your code a little: declare "r1", make
a() return a void pointer as that is the prototype for the thread
entry point, and check the return value of pthread_join().

The return value from pthread_join() does probably tell you something
like "No such process".

Why? Well, you created thread thread1 with default attributes. And they
happen to have the thread state set to DETACH. So, your new thread gets
created more or less independent from the 'main' thread. And at the point
of calling pthread_join() it's most likely non-existant.

Try creating a thread attribute object and change the state to
PTHREAD_CREATE_UNDETACHED like in

{
	...
	pthread_attr_t ta ;

	printf("Begin\n");
	e = pthread_attr_init ( &ta ) ;
	printf("pthread_attr_init error = %d,%s\n", e, strerror(e));
	e = pthread_attr_setdetachstate ( &ta, PTHREAD_CREATE_UNDETACHED ) ;
	printf("pthread_attr_setdetachstate error = %d,%s\n", e, strerror(e));
	e = pthread_create(&thread1, &ta, a, (void *) &r1);
	printf("Pthread_create error = %d,%s\n", e, strerror(e));
	...
}

I'd guess that this gives you the expected behavior.

Helmut


> having problems running threads on AIX. The following code
> produces the following error at runtime. any help would be nice:-).
> 
> 
> #include <stdio.h>
> #include <string.h>
> #include <pthread.h>
> 
> void a(int *arg)
> {
>         sleep(1);
>         printf("Thread A\n");
>         fflush(stdout);
> }
> 
> 
> main()
> {
>         pthread_t thread1, thread2;
>         int e;
> 
>         printf("Begin\n");
> 
>         e = pthread_create(&thread1, 0, (void *) a, (void *) &r1);
> 
>         printf("Pthread_create error = %s\n", strerror(e));
> 
>         pthread_join(thread1, 0);
> 
>         printf("End\n");
> }
> 
> 
> 
> Begin
> Pthread_create error = Invalid argument
> End
> 
> thanx nick
> 
> 
> 


-- 
Best regards, Helmut

--------------------------------------------------------------------------
Helmut Cossmann                             Phone    :    +49-6221-59-4552
IBM WT European Networking Center           Fax      :    +49-6221-59-3300
Broadband Multimedia Collaboration          Hauspost :            69115-55
Vangerowstrasse 18                          VNET     :   cossmann@heidelbg
69115 Heidelberg                            Internet : hc@heidelbg.ibm.com
--------------------------------------------------------------------------

home help back first fref pref prev next nref lref last post