[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Same old AIX problem
Good afternoon!
OpenLDAP-2.0-alpha2 is not able to detect a thread library on AIX 4.2.1.
The small program configure relies on to test various threads
configurations is the following:
----- Code STARTS
#include "confdefs.h"
/* pthread test headers */
#include <pthread.h>
#ifndef NULL
#define NULL (void*)0
#endif
static void *task(p)
void *p;
{
return (void *) (p == NULL);
}
int main(argc, argv)
int argc;
char **argv;
{
/* pthread test function */
pthread_t t;
int status;
/* make sure pthread_create() isn't just a stub */
#if HAVE_PTHREADS_D4
status = pthread_create(&t, pthread_attr_default, task, NULL);
#else
status = pthread_create(&t, NULL, task, NULL);
#endif
if( status ) exit( status );
/* make sure pthread_detach() isn't just a stub */
#if HAVE_PTHREADS_D4
status = pthread_detach( &t );
#else
status = pthread_detach( t );
#endif
#ifdef HAVE_LINUX_THREADS
pthread_kill_other_threads_np();
#endif
exit( status );
}
----- Code ENDS
Here's what happens:
...
-> HAVE_PTHREADS_D4 is not defined
status = pthread_create(&t, NULL, task, NULL);
-> OK status is 0 but as a default, threads are created DETACHED on AIX (!!!)
...
-> HAVE_PTHREADS_D4 is not defined
status = pthread_create(&t, NULL, task, NULL);
-> KAWABUNGA! status is 3!
Here's the code that should be used instead (I think it's more portable
even on <beeeeeep> OS'es like AIX):
----- Code STARTS
#include "confdefs.h"
/* pthread test headers */
#include <pthread.h>
#ifndef NULL
#define NULL (void*)0
#endif
static void *task(p)
void *p;
{
return (void *) (p == NULL);
}
int main(argc, argv)
int argc;
char **argv;
{
/* pthread test function */
pthread_t t;
pthread_attr_t attr;
int status;
/* set explicit default */
status = pthread_attr_init( &attr );
if( status ) exit( status );
#ifdef PTHREAD_CREATE_JOINABLE
status = pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE );
#else
status = pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
#endif
if( status ) exit( status );
/* some more default values could be set here */
/* an explicit default could also be set for pthread_attr_default ? */
/* make sure pthread_create() isn't just a stub */
#if HAVE_PTHREADS_D4
status = pthread_create(&t, pthread_attr_default, task, NULL);
#else
status = pthread_create(&t, &attr, task, NULL);
#endif
if( status ) exit( status );
/* make sure pthread_detach() isn't just a stub */
#if HAVE_PTHREADS_D4
status = pthread_detach( &t );
#else
status = pthread_detach( t );
#endif
#ifdef HAVE_LINUX_THREADS
pthread_kill_other_threads_np();
#endif
exit( status );
}
----- Code ENDS
Note that the same code should be used in thr_posix.c.
Ciya,
Frederic Poels.