linked with -lpthread.
+2005-07-25 Bruno Haible <bruno@clisp.org>
+
+ Make pthread_in_use() return 0 on Solaris and HP-UX when not linking
+ with -lpthread.
+ * lock.h (pthread_in_use) [PTHREAD_IN_USE_DETECTION_HARD]: Define
+ through glthread_in_use.
+ * lock.c (dummy_thread_func, glthread_in_use): New functions.
+
2005-07-22 Bruno Haible <bruno@clisp.org>
* Makefile.in (libintl.la, libgnuintl.la): Link with @LTLIBTHREADS@.
/* Use the POSIX threads library. */
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The function to be executed by a dummy thread. */
+static void *
+dummy_thread_func (void *arg)
+{
+ return arg;
+}
+
+int
+glthread_in_use (void)
+{
+ static int tested;
+ static int result; /* 1: linked with -lpthread, 0: only with libc */
+
+ if (!tested)
+ {
+ pthread_t thread;
+
+ if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
+ /* Thread creation failed. */
+ result = 0;
+ else
+ {
+ /* Thread creation works. */
+ void *retval;
+ if (pthread_join (thread, &retval) != 0)
+ abort ();
+ result = 1;
+ }
+ tested = 1;
+ }
+ return result;
+}
+
+# endif
+
/* -------------------------- gl_lock_t datatype -------------------------- */
/* ------------------------- gl_rwlock_t datatype ------------------------- */
# include <pthread.h>
# include <stdlib.h>
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The pthread_in_use() detection needs to be done at runtime. */
+# define pthread_in_use() \
+ glthread_in_use ()
+extern int glthread_in_use (void);
+
+# endif
+
# if USE_POSIX_THREADS_WEAK
/* Use weak references to the POSIX threads library. */
# pragma weak pthread_self
# endif
-# pragma weak pthread_cancel
-# define pthread_in_use() (pthread_cancel != NULL)
+# if !PTHREAD_IN_USE_DETECTION_HARD
+# pragma weak pthread_cancel
+# define pthread_in_use() (pthread_cancel != NULL)
+# endif
# else
-# define pthread_in_use() 1
+# if !PTHREAD_IN_USE_DETECTION_HARD
+# define pthread_in_use() 1
+# endif
# endif
+2005-07-25 Bruno Haible <bruno@clisp.org>
+
+ * lock.m4 (gl_LOCK): On Solaris and HP-UX, define
+ PTHREAD_IN_USE_DETECTION_HARD.
+ * gettext.m4 (AM_INTL_SUBDIR): Also hide the glthread_in_use function.
+
2005-07-22 Bruno Haible <bruno@clisp.org>
* lock.m4 (gl_LOCK): Stronger test for pthread functions in libc, so
#define __libc_lock_init_recursive gl_recursive_lock_init
#define __libc_lock_lock_recursive gl_recursive_lock_lock
#define __libc_lock_unlock_recursive gl_recursive_lock_unlock
+#define glthread_in_use libintl_thread_in_use
#define glthread_lock_init libintl_lock_init
#define glthread_lock_lock libintl_lock_lock
#define glthread_lock_unlock libintl_lock_unlock
# The program links fine without libpthread. But it may actually
# need to link with libpthread in order to create multiple threads.
AC_CHECK_LIB(pthread, pthread_kill,
- [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread])
+ [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread
+ # On Solaris and HP-UX, most pthread functions exist also in libc.
+ # Therefore pthread_in_use() needs to actually try to create a
+ # thread: pthread_create from libc will fail, whereas
+ # pthread_create will actually create a thread.
+ case "$host_os" in
+ solaris* | hpux*)
+ AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], 1,
+ [Define if the pthread_in_use() detection is hard.])
+ esac
+ ])
else
# Some library is needed. Try libpthread and libc_r.
AC_CHECK_LIB(pthread, pthread_kill,
dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK
dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK
dnl
-dnl HP-UX 11 posix -lpthread Y OK
+dnl HP-UX 11 posix -lpthread N (cc) OK
+dnl Y (gcc)
dnl
dnl IRIX 6.5 posix -lpthread Y 0.5
dnl