[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
pthread-h: fix link errors with --enable-threads=isoc on AIX
From: |
Bruno Haible |
Subject: |
pthread-h: fix link errors with --enable-threads=isoc on AIX |
Date: |
Mon, 02 Dec 2019 02:59:51 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-166-generic; KDE/5.18.0; x86_64; ; ) |
On AIX, building gnulib with --enable-threads=isoc produces a couple of link
errors:
gmake[4]: Entering directory `/home/haible/testdir1/build-64-xlc/gltests'
xlc -q64 -qthreaded -qtls -g -L/home/haible/prefix64/lib -o test-pthread-cond
test-pthread-cond.o libtests.a ../gllib/libgnu.a libtests.a -lm -lm -lm -lm
-lm -lm -lm -lm -lm -lm
ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_create
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_signal
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-317 ERROR: Undefined symbol: .pthread_join
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_settype
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_wait
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_timedwait
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
gmake[4]: *** [test-pthread-cond] Error 8
xlc -q64 -qthreaded -qtls -g -L/home/haible/prefix64/lib -o
test-pthread-mutex test-pthread-mutex.o libtests.a ../gllib/libgnu.a libtests.a
-lm -lm -lm -lm -lm -lm -lm -lm -lm -lm
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_settype
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_create
ld: 0711-317 ERROR: Undefined symbol: .pthread_join
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
gmake[4]: *** [test-pthread-mutex] Error 8
xlc -q64 -qthreaded -qtls -g -L/home/haible/prefix64/lib -o
test-pthread-once1 test-pthread-once1.o libtests.a ../gllib/libgnu.a libtests.a
-lm -lm -lm -lm -lm -lm -lm -lm -lm -lm
ld: 0711-317 ERROR: Undefined symbol: .pthread_once
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
gmake[4]: *** [test-pthread-once1] Error 8
xlc -q64 -qthreaded -qtls -g -L/home/haible/prefix64/lib -o
test-pthread-once2 test-pthread-once2.o libtests.a ../gllib/libgnu.a libtests.a
-lm -lm -lm -lm -lm -lm -lm -lm -lm -lm
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_settype
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_wait
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_timedwait
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_signal
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_broadcast
ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_create
ld: 0711-317 ERROR: Undefined symbol: .pthread_join
ld: 0711-317 ERROR: Undefined symbol: .pthread_once
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
gmake[4]: *** [test-pthread-once2] Error 8
xlc -q64 -qthreaded -qtls -g -L/home/haible/prefix64/lib -o
test-pthread-rwlock test-pthread-rwlock.o libtests.a ../gllib/libgnu.a
libtests.a -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_settype
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_create
ld: 0711-317 ERROR: Undefined symbol: .pthread_join
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_wait
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_timedwait
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_signal
ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_broadcast
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
gmake[4]: *** [test-pthread-rwlock] Error 8
xlc -q64 -qthreaded -qtls -g -L/home/haible/prefix64/lib -o
test-pthread-thread test-pthread-thread.o libtests.a ../gllib/libgnu.a
libtests.a -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm
ld: 0711-317 ERROR: Undefined symbol: .pthread_self
ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_create
ld: 0711-317 ERROR: Undefined symbol: .pthread_join
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
gmake[4]: *** [test-pthread-thread] Error 8
xlc -q64 -qthreaded -qtls -g -L/home/haible/prefix64/lib -o test-pthread-tss
test-pthread-tss.o libtests.a ../gllib/libgnu.a libtests.a -lm -lm -lm -lm
-lm -lm -lm -lm -lm -lm
ld: 0711-317 ERROR: Undefined symbol: .pthread_key_create
ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_create
ld: 0711-317 ERROR: Undefined symbol: .pthread_join
ld: 0711-317 ERROR: Undefined symbol: .pthread_key_delete
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_settype
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_getspecific
ld: 0711-317 ERROR: Undefined symbol: .pthread_setspecific
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
gmake[4]: *** [test-pthread-tss] Error 8
The reason is that --enable-threads=isoc has the effect of setting $LIBTHREAD
and $LIBMULTITHREAD to empty - because the function mtx_lock, thrd_create, etc.
are in libc. But the functions pthread_mutex_lock, pthread_create etc. are
still only in available with '-lpthread'. Therefore programs which use the POSIX
threads API instead of the lock, cond, tls, thread modules require '-lpthread'.
This patch fixes the issue by defining two additional variable $LIBPTHREAD and
$LIBPMULTITHREAD, that are like $LIBTHREAD and $LIBMULTITHREAD, except that they
are relevant for the POSIX threads API.
Tested on AIX, glibc, and Solaris OpenIndiana. Here are the values determined
by threadlib.m4:
Without --enable-threads option (equivalent to --enable-threads=posix):
AIX glibc Solaris OpenIndiana
LIBTHREAD "-lpthread" "" ""
LIBMULTITHREAD "-lpthread" "-pthread" "-lpthread"
LIBPTHREAD "-lpthread" "-pthread" ""
LIBPMULTITHREAD "-lpthread" "-pthread" "-lpthread"
With --enable-threads=isoc:
AIX glibc Solaris OpenIndiana
CC="gcc -pthread"
LIBTHREAD "" "" ""
LIBMULTITHREAD "" "" ""
LIBPTHREAD "-lpthread" "" ""
LIBPMULTITHREAD "-lpthread" "-lpthread" "-lpthread"
With --enable-threads=isoc+posix:
AIX glibc Solaris OpenIndiana
CC="gcc -pthread"
LIBTHREAD "" "" ""
LIBMULTITHREAD "-lpthread" "-lpthread" "-lpthread"
LIBPTHREAD "-lpthread" "" ""
LIBPMULTITHREAD "-lpthread" "-lpthread" "-lpthread"
2019-12-01 Bruno Haible <address@hidden>
pthread-h: Fix link errors with --enable-threads=isoc on AIX.
* m4/threadlib.m4 (gl_ANYTHREADLIB_EARLY): New macro, extracted from
gl_THREADLIB_EARLY_BODY.
(gl_THREADLIB_EARLY_BODY): Invoke it.
(gl_PTHREADLIB_BODY): New macro, extracted from gl_THREADLIB_BODY.
(gl_THREADLIB_BODY): Invoke it.
(gl_PTHREADLIB): New macro.
* m4/pthread_h.m4 (gl_PTHREAD_H): Require gl_PTHREADLIB. Require
gl_THREADLIB and test $gl_threads_api only if module 'threadlib' is
present. Define LIB_PTHREAD using LIBPMULTITHREAD, not LIBMULTITHREAD.
* modules/pthread-h (Files): Add threadlib.m4.
(Depends-on): Remove threadlib.
(configure.ac-early): Invoke gl_ANYTHREADLIB_EARLY. Don't set _REENTRANT
and _THREAD_SAFE here.
(Link): Use LIBPTHREAD, not LIBTHREAD.
* modules/pthread-thread (Link): Use LIBPMULTITHREAD, not
LIBMULTITHREAD.
* modules/pthread-once (Link): Likewise.
* modules/pthread-mutex (Link): Likewise.
* modules/pthread-rwlock (Link): Likewise.
* modules/pthread-cond (Link): Likewise.
* modules/pthread-tss (Link): Likewise.
* modules/pthread-spin (Link): Likewise.
* modules/pthread (Link): Likewise.
* modules/pthread-h-c++-tests (test_pthread_c___LDADD): Likewise.
* modules/pthread-thread-tests (test_pthread_thread_LDADD): Likewise.
* modules/pthread-once-tests (test_pthread_once1_LDADD,
test_pthread_once2_LDADD): Likewise.
* modules/pthread-mutex-tests (test_pthread_mutex_LDADD): Likewise.
* modules/pthread-rwlock-tests (test_pthread_rwlock_LDADD): Likewise.
* modules/pthread-cond-tests (test_pthread_cond_LDADD): Likewise.
* modules/pthread-tss-tests (test_pthread_tss_LDADD): Likewise.
diff --git a/m4/pthread_h.m4 b/m4/pthread_h.m4
index 8c23a77..bccad23 100644
--- a/m4/pthread_h.m4
+++ b/m4/pthread_h.m4
@@ -1,4 +1,4 @@
-# pthread_h.m4 serial 4
+# pthread_h.m4 serial 5
dnl Copyright (C) 2009-2019 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -10,13 +10,21 @@ AC_DEFUN([gl_PTHREAD_H],
dnl once only, before all statements that occur in other macros.
AC_REQUIRE([gl_PTHREAD_H_DEFAULTS])
- AC_REQUIRE([gl_THREADLIB])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_REQUIRE([gl_PTHREADLIB])
gl_CHECK_NEXT_HEADERS([pthread.h])
- dnl On mingw, if --enable-threads=windows or gl_AVOID_WINPTHREAD is used,
- dnl ignore the <pthread.h> from the mingw-w64 winpthreads library.
- if test $ac_cv_header_pthread_h = yes && test $gl_threads_api != windows;
then
+ if test $ac_cv_header_pthread_h = yes; then
HAVE_PTHREAD_H=1
+ dnl On mingw, if --enable-threads=windows or gl_AVOID_WINPTHREAD is used,
+ dnl ignore the <pthread.h> from the mingw-w64 winpthreads library.
+ m4_ifdef([gl_][THREADLIB], [
+ AC_REQUIRE([gl_][THREADLIB])
+ if { case "$host_os" in mingw*) true;; *) false;; esac; } \
+ && test $gl_threads_api = windows; then
+ HAVE_PTHREAD_H=0
+ fi
+ ])
else
HAVE_PTHREAD_H=0
fi
@@ -125,7 +133,7 @@ AC_DEFUN([gl_PTHREAD_H],
AC_REQUIRE([AC_C_RESTRICT])
dnl For backward compatibility with gnulib versions <= 2019-07.
- LIB_PTHREAD="$LIBMULTITHREAD"
+ LIB_PTHREAD="$LIBPMULTITHREAD"
AC_SUBST([LIB_PTHREAD])
])
diff --git a/m4/threadlib.m4 b/m4/threadlib.m4
index 7972cfa..d22e0d6 100644
--- a/m4/threadlib.m4
+++ b/m4/threadlib.m4
@@ -1,4 +1,4 @@
-# threadlib.m4 serial 21
+# threadlib.m4 serial 22
dnl Copyright (C) 2005-2019 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -8,6 +8,17 @@ dnl From Bruno Haible.
AC_PREREQ([2.60])
+dnl gl_PTHREADLIB
+dnl -------------
+dnl Tests for the libraries needs for using the POSIX threads API.
+dnl Sets the variable LIBPTHREAD to the linker options for use in a Makefile.
+dnl Sets the variable LIBPMULTITHREAD, for programs that really need
+dnl multithread functionality. The difference between LIBPTHREAD and
+dnl LIBPMULTITHREAD is that on platforms supporting weak symbols, typically
+dnl LIBPTHREAD is empty whereas LIBPMULTITHREAD is not.
+dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
+dnl multithread-safe programs.
+
dnl gl_THREADLIB
dnl ------------
dnl Tests for a multithreading library to be used.
@@ -36,6 +47,32 @@ dnl Since support for GNU pth was removed, $LTLIBTHREAD and
$LIBTHREAD have the
dnl same value, and similarly $LTLIBMULTITHREAD and $LIBMULTITHREAD have the
dnl same value. Only system libraries are needed.
+AC_DEFUN([gl_ANYTHREADLIB_EARLY],
+[
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ if test -z "$gl_anythreadlib_early_done"; then
+ case "$host_os" in
+ osf*)
+ # On OSF/1, the compiler needs the flag -D_REENTRANT so that it
+ # groks <pthread.h>. cc also understands the flag -pthread, but
+ # we don't use it because 1. gcc-2.95 doesn't understand -pthread,
+ # 2. putting a flag into CPPFLAGS that has an effect on the linker
+ # causes the AC_LINK_IFELSE test below to succeed unexpectedly,
+ # leading to wrong values of LIBTHREAD and LTLIBTHREAD.
+ CPPFLAGS="$CPPFLAGS -D_REENTRANT"
+ ;;
+ esac
+ # Some systems optimize for single-threaded programs by default, and
+ # need special flags to disable these optimizations. For example, the
+ # definition of 'errno' in <errno.h>.
+ case "$host_os" in
+ aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;;
+ solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;;
+ esac
+ gl_anythreadlib_early_done=done
+ fi
+])
+
AC_DEFUN([gl_THREADLIB_EARLY],
[
AC_REQUIRE([gl_THREADLIB_EARLY_BODY])
@@ -99,24 +136,91 @@ changequote([,])dnl
|| test "$gl_use_threads" = posix \
|| test "$gl_use_threads" = isoc+posix; then
# For using <threads.h> or <pthread.h>:
- case "$host_os" in
- osf*)
- # On OSF/1, the compiler needs the flag -D_REENTRANT so that it
- # groks <pthread.h>. cc also understands the flag -pthread, but
- # we don't use it because 1. gcc-2.95 doesn't understand -pthread,
- # 2. putting a flag into CPPFLAGS that has an effect on the linker
- # causes the AC_LINK_IFELSE test below to succeed unexpectedly,
- # leading to wrong values of LIBTHREAD and LTLIBTHREAD.
- CPPFLAGS="$CPPFLAGS -D_REENTRANT"
- ;;
- esac
- # Some systems optimize for single-threaded programs by default, and
- # need special flags to disable these optimizations. For example, the
- # definition of 'errno' in <errno.h>.
- case "$host_os" in
- aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;;
- solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;;
- esac
+ gl_ANYTHREADLIB_EARLY
+ fi
+])
+
+dnl The guts of gl_PTHREADLIB. Needs to be expanded only once.
+
+AC_DEFUN([gl_PTHREADLIB_BODY],
+[
+ AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
+ if test -z "$gl_threadlib_body_done"; then
+ gl_pthread_api=no
+ LIBPTHREAD=
+ LIBPMULTITHREAD=
+ # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that
+ # it groks <pthread.h>. It's added above, in gl_ANYTHREADLIB_EARLY.
+ AC_CHECK_HEADER([pthread.h],
+ [gl_have_pthread_h=yes], [gl_have_pthread_h=no])
+ if test "$gl_have_pthread_h" = yes; then
+ # Other possible tests:
+ # -lpthreads (FSU threads, PCthreads)
+ # -lgthreads
+ # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist
+ # in libc. IRIX 6.5 has the first one in both libc and libpthread, but
+ # the second one only in libpthread, and lock.c needs it.
+ #
+ # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04
+ # needs -pthread for some reason. See:
+ # https://lists.gnu.org/r/bug-gnulib/2014-09/msg00023.html
+ save_LIBS=$LIBS
+ for gl_pthread in '' '-pthread'; do
+ LIBS="$LIBS $gl_pthread"
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <pthread.h>
+ pthread_mutex_t m;
+ pthread_mutexattr_t ma;
+ ]],
+ [[pthread_mutex_lock (&m);
+ pthread_mutexattr_init (&ma);]])],
+ [gl_pthread_api=yes
+ LIBPTHREAD=$gl_pthread
+ LIBPMULTITHREAD=$gl_pthread])
+ LIBS=$save_LIBS
+ test $gl_pthread_api = yes && break
+ done
+
+ # Test for libpthread by looking for pthread_kill. (Not pthread_self,
+ # since it is defined as a macro on OSF/1.)
+ if test $gl_pthread_api = yes && test -z "$LIBPTHREAD"; then
+ # 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],
+ [LIBPMULTITHREAD=-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.
+ # On Solaris 10 or newer, this test is no longer needed, because
+ # libc contains the fully functional pthread functions.
+ case "$host_os" in
+ solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*)
+ AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
+ [Define if the pthread_in_use() detection is hard.])
+ esac
+ ])
+ elif test $gl_pthread_api != yes; then
+ # Some library is needed. Try libpthread and libc_r.
+ AC_CHECK_LIB([pthread], [pthread_kill],
+ [gl_pthread_api=yes
+ LIBPTHREAD=-lpthread
+ LIBPMULTITHREAD=-lpthread])
+ if test $gl_pthread_api != yes; then
+ # For FreeBSD 4.
+ AC_CHECK_LIB([c_r], [pthread_kill],
+ [gl_pthread_api=yes
+ LIBPTHREAD=-lc_r
+ LIBPMULTITHREAD=-lc_r])
+ fi
+ fi
+ fi
+ AC_MSG_CHECKING([whether POSIX threads API is available])
+ AC_MSG_RESULT([$gl_pthread_api])
+ AC_SUBST([LIBPTHREAD])
+ AC_SUBST([LIBPMULTITHREAD])
+ gl_threadlib_body_done=done
fi
])
@@ -198,89 +302,24 @@ int main ()
if test "$gl_use_threads" = yes \
|| test "$gl_use_threads" = posix \
|| test "$gl_use_threads" = isoc+posix; then
- # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that
- # it groks <pthread.h>. It's added above, in gl_THREADLIB_EARLY_BODY.
- AC_CHECK_HEADER([pthread.h],
- [gl_have_pthread_h=yes], [gl_have_pthread_h=no])
- if test "$gl_have_pthread_h" = yes; then
- # Other possible tests:
- # -lpthreads (FSU threads, PCthreads)
- # -lgthreads
- gl_have_pthread=
- # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist
- # in libc. IRIX 6.5 has the first one in both libc and libpthread, but
- # the second one only in libpthread, and lock.c needs it.
- #
- # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04
- # needs -pthread for some reason. See:
- # https://lists.gnu.org/r/bug-gnulib/2014-09/msg00023.html
- save_LIBS=$LIBS
- for gl_pthread in '' '-pthread'; do
- LIBS="$LIBS $gl_pthread"
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM(
- [[#include <pthread.h>
- pthread_mutex_t m;
- pthread_mutexattr_t ma;
- ]],
- [[pthread_mutex_lock (&m);
- pthread_mutexattr_init (&ma);]])],
- [gl_have_pthread=yes
- LIBTHREAD=$gl_pthread LTLIBTHREAD=$gl_pthread
- LIBMULTITHREAD=$gl_pthread LTLIBMULTITHREAD=$gl_pthread])
- LIBS=$save_LIBS
- test -n "$gl_have_pthread" && break
- done
-
- # Test for libpthread by looking for pthread_kill. (Not pthread_self,
- # since it is defined as a macro on OSF/1.)
- if test -n "$gl_have_pthread" && test -z "$LIBTHREAD"; then
- # 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
- # 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.
- # On Solaris 10 or newer, this test is no longer needed, because
- # libc contains the fully functional pthread functions.
- case "$host_os" in
- solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*)
- AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
- [Define if the pthread_in_use() detection is hard.])
- esac
- ])
- elif test -z "$gl_have_pthread"; then
- # Some library is needed. Try libpthread and libc_r.
- AC_CHECK_LIB([pthread], [pthread_kill],
- [gl_have_pthread=yes
- LIBTHREAD=-lpthread LTLIBTHREAD=-lpthread
- LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread])
- if test -z "$gl_have_pthread"; then
- # For FreeBSD 4.
- AC_CHECK_LIB([c_r], [pthread_kill],
- [gl_have_pthread=yes
- LIBTHREAD=-lc_r LTLIBTHREAD=-lc_r
- LIBMULTITHREAD=-lc_r LTLIBMULTITHREAD=-lc_r])
- fi
- fi
- if test -n "$gl_have_pthread"; then
- if test "$gl_use_threads" = isoc+posix && test
"$gl_have_isoc_threads" = yes; then
- gl_threads_api='isoc+posix'
- AC_DEFINE([USE_ISOC_AND_POSIX_THREADS], [1],
- [Define if the combination of the ISO C and POSIX multithreading
APIs can be used.])
- LIBTHREAD= LTLIBTHREAD=
- else
- gl_threads_api=posix
- AC_DEFINE([USE_POSIX_THREADS], [1],
- [Define if the POSIX multithreading library can be used.])
- if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then
- if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
- AC_DEFINE([USE_POSIX_THREADS_WEAK], [1],
- [Define if references to the POSIX multithreading library
should be made weak.])
- LIBTHREAD= LTLIBTHREAD=
- fi
+ gl_PTHREADLIB_BODY
+ LIBTHREAD=$LIBPTHREAD LTLIBTHREAD=$LIBPTHREAD
+ LIBMULTITHREAD=$LIBPMULTITHREAD LTLIBMULTITHREAD=$LIBPMULTITHREAD
+ if test $gl_pthread_api = yes; then
+ if test "$gl_use_threads" = isoc+posix && test "$gl_have_isoc_threads"
= yes; then
+ gl_threads_api='isoc+posix'
+ AC_DEFINE([USE_ISOC_AND_POSIX_THREADS], [1],
+ [Define if the combination of the ISO C and POSIX multithreading
APIs can be used.])
+ LIBTHREAD= LTLIBTHREAD=
+ else
+ gl_threads_api=posix
+ AC_DEFINE([USE_POSIX_THREADS], [1],
+ [Define if the POSIX multithreading library can be used.])
+ if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then
+ if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
+ AC_DEFINE([USE_POSIX_THREADS_WEAK], [1],
+ [Define if references to the POSIX multithreading library
should be made weak.])
+ LIBTHREAD= LTLIBTHREAD=
fi
fi
fi
@@ -317,6 +356,12 @@ int main ()
AC_SUBST([LTLIBMULTITHREAD])
])
+AC_DEFUN([gl_PTHREADLIB],
+[
+ AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
+ gl_PTHREADLIB_BODY
+])
+
AC_DEFUN([gl_THREADLIB],
[
AC_REQUIRE([gl_THREADLIB_EARLY])
diff --git a/modules/pthread b/modules/pthread
index c9c5614..455b73e 100644
--- a/modules/pthread
+++ b/modules/pthread
@@ -21,7 +21,7 @@ Include:
<pthread.h>
Link:
-$(LIBMULTITHREAD)
+$(LIBPMULTITHREAD)
License:
LGPLv2+
diff --git a/modules/pthread-cond b/modules/pthread-cond
index c07aa63..e5c62fe 100644
--- a/modules/pthread-cond
+++ b/modules/pthread-cond
@@ -23,7 +23,7 @@ Include:
<pthread.h>
Link:
-$(LIBMULTITHREAD)
+$(LIBPMULTITHREAD)
License:
LGPLv2+
diff --git a/modules/pthread-cond-tests b/modules/pthread-cond-tests
index 8334b3b..041047e 100644
--- a/modules/pthread-cond-tests
+++ b/modules/pthread-cond-tests
@@ -13,4 +13,4 @@ configure.ac:
Makefile.am:
TESTS += test-pthread-cond
check_PROGRAMS += test-pthread-cond
-test_pthread_cond_LDADD = $(LDADD) @LIBMULTITHREAD@ @YIELD_LIB@
+test_pthread_cond_LDADD = $(LDADD) @LIBPMULTITHREAD@ @YIELD_LIB@
diff --git a/modules/pthread-h b/modules/pthread-h
index 3a9c150..3fe5527 100644
--- a/modules/pthread-h
+++ b/modules/pthread-h
@@ -4,21 +4,20 @@ A POSIX-like <pthread.h>.
Files:
lib/pthread.in.h
m4/pthread_h.m4
+m4/threadlib.m4
Depends-on:
extensions
extern-inline
sched
time
-threadlib
snippet/c++defs
snippet/_Noreturn
snippet/arg-nonnull
snippet/warn-on-use
configure.ac-early:
-AC_DEFINE([_REENTRANT], 1, [For thread-safety on OSF/1, Solaris.])
-AC_DEFINE([_THREAD_SAFE], 1, [For thread-safety on AIX, FreeBSD.])
+gl_ANYTHREADLIB_EARLY
configure.ac:
gl_PTHREAD_H
@@ -166,7 +165,7 @@ Include:
<pthread.h>
Link:
-$(LIBTHREAD)
+$(LIBPTHREAD)
License:
LGPLv2+
diff --git a/modules/pthread-h-c++-tests b/modules/pthread-h-c++-tests
index 225c7f8..f69f4e1 100644
--- a/modules/pthread-h-c++-tests
+++ b/modules/pthread-h-c++-tests
@@ -15,5 +15,5 @@ if ANSICXX
TESTS += test-pthread-c++
check_PROGRAMS += test-pthread-c++
test_pthread_c___SOURCES = test-pthread-c++.cc
-test_pthread_c___LDADD = $(LDADD) $(LIBMULTITHREAD)
+test_pthread_c___LDADD = $(LDADD) $(LIBPMULTITHREAD)
endif
diff --git a/modules/pthread-mutex b/modules/pthread-mutex
index 71496b7..556ffa8 100644
--- a/modules/pthread-mutex
+++ b/modules/pthread-mutex
@@ -25,7 +25,7 @@ Include:
<pthread.h>
Link:
-$(LIBTHREAD) or $(LIBMULTITHREAD)
+$(LIBPTHREAD) or $(LIBPMULTITHREAD)
License:
LGPLv2+
diff --git a/modules/pthread-mutex-tests b/modules/pthread-mutex-tests
index 050d506..9d9861f 100644
--- a/modules/pthread-mutex-tests
+++ b/modules/pthread-mutex-tests
@@ -11,4 +11,4 @@ configure.ac:
Makefile.am:
TESTS += test-pthread-mutex
check_PROGRAMS += test-pthread-mutex
-test_pthread_mutex_LDADD = $(LDADD) @LIBMULTITHREAD@ @YIELD_LIB@
+test_pthread_mutex_LDADD = $(LDADD) @LIBPMULTITHREAD@ @YIELD_LIB@
diff --git a/modules/pthread-once b/modules/pthread-once
index 3e25c76..c7f28d1 100644
--- a/modules/pthread-once
+++ b/modules/pthread-once
@@ -22,7 +22,7 @@ Include:
<pthread.h>
Link:
-$(LIBMULTITHREAD)
+$(LIBPMULTITHREAD)
License:
LGPLv2+
diff --git a/modules/pthread-once-tests b/modules/pthread-once-tests
index 2765c30..17b25b6 100644
--- a/modules/pthread-once-tests
+++ b/modules/pthread-once-tests
@@ -13,5 +13,5 @@ configure.ac:
Makefile.am:
TESTS += test-pthread-once1 test-pthread-once2
check_PROGRAMS += test-pthread-once1 test-pthread-once2
-test_pthread_once1_LDADD = $(LDADD) @LIBMULTITHREAD@
-test_pthread_once2_LDADD = $(LDADD) @LIBMULTITHREAD@ @YIELD_LIB@
+test_pthread_once1_LDADD = $(LDADD) @LIBPMULTITHREAD@
+test_pthread_once2_LDADD = $(LDADD) @LIBPMULTITHREAD@ @YIELD_LIB@
diff --git a/modules/pthread-rwlock b/modules/pthread-rwlock
index cb30e44..e935414 100644
--- a/modules/pthread-rwlock
+++ b/modules/pthread-rwlock
@@ -24,7 +24,7 @@ Include:
<pthread.h>
Link:
-$(LIBTHREAD) or $(LIBMULTITHREAD)
+$(LIBPTHREAD) or $(LIBPMULTITHREAD)
License:
LGPLv2+
diff --git a/modules/pthread-rwlock-tests b/modules/pthread-rwlock-tests
index ddb64dc..a8d51ee 100644
--- a/modules/pthread-rwlock-tests
+++ b/modules/pthread-rwlock-tests
@@ -12,4 +12,4 @@ configure.ac:
Makefile.am:
TESTS += test-pthread-rwlock
check_PROGRAMS += test-pthread-rwlock
-test_pthread_rwlock_LDADD = $(LDADD) @LIBMULTITHREAD@ @YIELD_LIB@
+test_pthread_rwlock_LDADD = $(LDADD) @LIBPMULTITHREAD@ @YIELD_LIB@
diff --git a/modules/pthread-spin b/modules/pthread-spin
index a58b9f7..53e0051 100644
--- a/modules/pthread-spin
+++ b/modules/pthread-spin
@@ -22,7 +22,7 @@ Include:
<pthread.h>
Link:
-$(LIBMULTITHREAD)
+$(LIBPMULTITHREAD)
License:
LGPLv2+
diff --git a/modules/pthread-thread b/modules/pthread-thread
index b9133d8..af6682b 100644
--- a/modules/pthread-thread
+++ b/modules/pthread-thread
@@ -22,7 +22,7 @@ Include:
<pthread.h>
Link:
-$(LIBMULTITHREAD)
+$(LIBPMULTITHREAD)
License:
LGPLv2+
diff --git a/modules/pthread-thread-tests b/modules/pthread-thread-tests
index 497ce4f..fde0e0a 100644
--- a/modules/pthread-thread-tests
+++ b/modules/pthread-thread-tests
@@ -9,4 +9,4 @@ configure.ac:
Makefile.am:
TESTS += test-pthread-thread
check_PROGRAMS += test-pthread-thread
-test_pthread_thread_LDADD = $(LDADD) @LIBMULTITHREAD@
+test_pthread_thread_LDADD = $(LDADD) @LIBPMULTITHREAD@
diff --git a/modules/pthread-tss b/modules/pthread-tss
index f4e2fde..ab95d08 100644
--- a/modules/pthread-tss
+++ b/modules/pthread-tss
@@ -22,7 +22,7 @@ Include:
<pthread.h>
Link:
-$(LIBMULTITHREAD)
+$(LIBPMULTITHREAD)
License:
LGPLv2+
diff --git a/modules/pthread-tss-tests b/modules/pthread-tss-tests
index 52707e3..3a33e56 100644
--- a/modules/pthread-tss-tests
+++ b/modules/pthread-tss-tests
@@ -12,4 +12,4 @@ configure.ac:
Makefile.am:
TESTS += test-pthread-tss
check_PROGRAMS += test-pthread-tss
-test_pthread_tss_LDADD = $(LDADD) @LIBMULTITHREAD@ @YIELD_LIB@
+test_pthread_tss_LDADD = $(LDADD) @LIBPMULTITHREAD@ @YIELD_LIB@
- pthread-h: fix link errors with --enable-threads=isoc on AIX,
Bruno Haible <=