[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: Multi-threaded slapd on AIX 4.2.1



At 06:56 PM 4/9/00 -0700, Howard Chu wrote:
>> -----Original Message-----
>> From: Kurt D. Zeilenga [mailto:Kurt@OpenLDAP.org]
>> At 12:29 AM 4/8/00 -0700, Howard Chu wrote:
>> >None of the AIX documentation even mentions the pthread_detach()
>> function,
>> >although it is present in pthread.h and in the library. At this point, my
>> >configure is complaining that pthread_create() is incompatible,
>> because the
>> >test program gets an ESRCH returned from pthread_detach().
>>
>> ESRCH implies a D4 vs final mismatch between the header and the library.
>>
>> >Got any ideas how to modify this particular test?
>>
>> Does pthread.h have multiple pthread_*() prototypes?  conditional
>> (-D) on what?
>> Does AIX have multiple pthread libraries?  conditional (-l) on what?
>
>Well, it has both a pthreads library and a dcepthreads library for DCE, but
>I'm definitely not trying to use the DCE stuff.

Just for clarification, DCE is Pthreads Draft 4.  Is pthread.h you are
using for DCE pthreads or POSIX threads?  Is there a conditional to get
appropriate behavior.

>The pthread_detach() returns
>ESRCH because the thread was already detached, 

Odd, my pthread_detach() man page calling pthread_detach with
an invalid pthread handle should return ESRCH and calling with
a non-joinable thread should return EINVAL.

Anyways....

>since AIX 4.2's
>pthread_create creates detached threads by default.

AIX is broken.  pthread_create() should create joinable threads by
default.

What happens if you create a thread and then attempt to call
pthread_join() on it?

What happens if you use DCE pthreads instead?

>Just for the sake of
>getting thru the configure script, I added a "#define HAVE_AIX_THREADS 1" to
>confdefs.h and added a check for it in the test. If true, I do a
>pthread_attr_setdetachstate() with
>PTHREAD_CREATE_UNDETACHED, so the newly created thread can be
>pthread_detach'd successfully.

I would suggest we detect (configure) this case by using:
	pthread_create()/pthread_attr_getdetachstate()
with verification by
	pthread_attr_getdetachstate()/pthread_create()

then define:
	NEEDS_PTHREAD_ATTR_SETDETACHSTATE_JOINABLE
	
We can also define PTHREAD_CREATE_JOINABLE to PTHREAD_CREATE_UNDETACHED
when PTHREAD_CREATE_JOINABLE is missing.

>In libldap_r/thr_posix.c, I decided to base the check on
>#if defined(HAVE_PTHREADS_FINAL) && defined(PTHREAD_CREATE_UNDETACHED)
>and do a similar pthread_attr_setdetachstate() to fix things. (AIX 4.2
>doesn't
>know about the PTHREAD_CREATE_JOINABLE flag but otherwise claims to be
>FINAL.)

I would prefer the HAVE_PTHREADS_FINAL and NEEDS... be defined if
pthread_attr_setdetachstate().  Basic flow:

#ifdef HAVE_PTHREADS_FINAL
	/* POSIX Threads */
#ifdef NEEDS_...
	/* AIX threads are broken... threads are not joinable by default */
	pthread_attr_setdetachstate()
#endif
	pthread_create()
#else
	/* DCE/D4 Pthreads
	pthread_create()
#endif
	if(detach) pthread_detach();