+2019-12-21 Bruno Haible <bruno@clisp.org>
+
+ threadlib: Fix LIBMULTITHREAD on FreeBSD with --enable-threads=isoc.
+ * m4/threadlib.m4 (gl_STDTHREADLIB_BODY): New macro (some code moved
+ here from m4/threads.m4).
+ (gl_THREADLIB_BODY): Don't test whether mtx_lock and cnd_timedwait exist
+ in libc. Instead, rely on gl_STDTHREADLIB_BODY.
+ (gl_STDTHREADLIB): New macro.
+ * m4/threads.m4 (gl_THREADS_H): Require gl_STDTHREADLIB instead of
+ gl_THREADLIB_BODY and gl_YIELD. Don't set LIBSTDTHREAD here.
+
2019-12-21 Bruno Haible <bruno@clisp.org>
sched_yield: Don't depend on threadlib and yield.
dnl Defines the C macro HAVE_PTHREAD_API if (at least parts of) the POSIX
dnl threads API is available.
+dnl gl_STDTHREADLIB
+dnl ---------------
+dnl Tests for the libraries needs for using the ISO C threads API.
+dnl Sets the variable LIBSTDTHREAD to the linker options for use in a Makefile.
+dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
+dnl multithread-safe programs.
+dnl Defines the C macro HAVE_THREADS_H if (at least parts of) the ISO C threads
+dnl API is available.
+
dnl gl_THREADLIB
dnl ------------
dnl Tests for a multithreading library to be used.
AC_DEFUN([gl_PTHREADLIB_BODY],
[
AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
- if test -z "$gl_threadlib_body_done"; then
+ if test -z "$gl_pthreadlib_body_done"; then
gl_pthread_api=no
LIBPTHREAD=
LIBPMULTITHREAD=
])
AC_SUBST([LIB_SCHED_YIELD])
- gl_threadlib_body_done=done
+ gl_pthreadlib_body_done=done
+ fi
+])
+
+dnl The guts of gl_STDTHREADLIB. Needs to be expanded only once.
+
+AC_DEFUN([gl_STDTHREADLIB_BODY],
+[
+ AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ if test -z "$gl_stdthreadlib_body_done"; then
+ AC_CHECK_HEADERS_ONCE([threads.h])
+
+ case "$host_os" in
+ mingw*)
+ LIBSTDTHREAD=
+ ;;
+ *)
+ gl_PTHREADLIB_BODY
+ if test $ac_cv_header_threads_h = yes; then
+ dnl glibc >= 2.29 has thrd_create in libpthread.
+ dnl FreeBSD >= 10 has thrd_create in libstdthreads; this library depends
+ dnl on libpthread (for the symbol 'pthread_mutexattr_gettype').
+ dnl AIX >= 7.1 and Solaris >= 11.4 have thrd_create in libc.
+ AC_CHECK_FUNCS([thrd_create])
+ if test $ac_cv_func_thrd_create = yes; then
+ LIBSTDTHREAD=
+ else
+ AC_CHECK_LIB([stdthreads], [thrd_create], [
+ LIBSTDTHREAD='-lstdthreads -lpthread'
+ ], [
+ dnl Guess that thrd_create is in libpthread.
+ LIBSTDTHREAD="$LIBPMULTITHREAD"
+ ])
+ fi
+ else
+ dnl Libraries needed by thrd.c, mtx.c, cnd.c, tss.c.
+ LIBSTDTHREAD="$LIBPMULTITHREAD $LIB_SCHED_YIELD"
+ fi
+ ;;
+ esac
+ AC_SUBST([LIBSTDTHREAD])
+
+ AC_MSG_CHECKING([whether ISO C threads API is available])
+ AC_MSG_RESULT([$ac_cv_header_threads_h])
+ gl_stdthreadlib_body_done=done
fi
])
fi
if test "$gl_use_threads" = isoc || test "$gl_use_threads" = isoc+posix; then
AC_CHECK_HEADERS_ONCE([threads.h])
- if test $ac_cv_header_threads_h = yes; then
- gl_have_isoc_threads=
- # Test whether both mtx_lock and cnd_timedwait exist in libc.
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM(
- [[#include <threads.h>
- #include <stddef.h>
- mtx_t m;
- cnd_t c;
- ]],
- [[mtx_lock (&m);
- cnd_timedwait (&c, &m, NULL);]])],
- [gl_have_isoc_threads=yes])
- fi
+ gl_have_isoc_threads="$ac_cv_header_threads_h"
fi
if test "$gl_use_threads" = yes \
|| test "$gl_use_threads" = posix \
fi
if test $gl_threads_api = none; then
if test "$gl_use_threads" = isoc && test "$gl_have_isoc_threads" = yes; then
+ gl_STDTHREADLIB_BODY
+ LIBTHREAD=$LIBSTDTHREAD LTLIBTHREAD=$LIBSTDTHREAD
+ LIBMULTITHREAD=$LIBSTDTHREAD LTLIBMULTITHREAD=$LIBSTDTHREAD
gl_threads_api=isoc
AC_DEFINE([USE_ISOC_THREADS], [1],
[Define if the ISO C multithreading library can be used.])
gl_PTHREADLIB_BODY
])
+AC_DEFUN([gl_STDTHREADLIB],
+[
+ AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
+ gl_STDTHREADLIB_BODY
+])
+
AC_DEFUN([gl_THREADLIB],
[
AC_REQUIRE([gl_THREADLIB_EARLY])
[
AC_REQUIRE([gl_THREADS_H_DEFAULTS])
AC_REQUIRE([AC_CANONICAL_HOST])
- AC_REQUIRE([gl_THREADLIB_BODY])
+ AC_REQUIRE([gl_STDTHREADLIB])
gl_CHECK_NEXT_HEADERS([threads.h])
if test $ac_cv_header_threads_h = yes; then
fi
fi
- case "$host_os" in
- mingw*)
- LIBSTDTHREAD=
- ;;
- *)
- if test $ac_cv_header_threads_h = yes; then
- dnl glibc >= 2.29 has thrd_create in libpthread.
- dnl FreeBSD >= 10 has thrd_create in libstdthreads; this library depends
- dnl on libpthread (for the symbol 'pthread_mutexattr_gettype').
- dnl AIX >= 7.1 and Solaris >= 11.4 have thrd_create in libc.
- AC_CHECK_FUNCS([thrd_create])
- if test $ac_cv_func_thrd_create = yes; then
- LIBSTDTHREAD=
- else
- AC_CHECK_LIB([stdthreads], [thrd_create], [
- LIBSTDTHREAD='-lstdthreads -lpthread'
- ], [
- dnl Guess that thrd_create is in libpthread.
- LIBSTDTHREAD="$LIBMULTITHREAD"
- ])
- fi
- else
- dnl Libraries needed by thrd.c, mtx.c, cnd.c, tss.c.
- LIBSTDTHREAD="$LIBMULTITHREAD $LIB_SCHED_YIELD"
- fi
- ;;
- esac
- AC_SUBST([LIBSTDTHREAD])
-
dnl Define _Thread_local.
dnl GCC, for example, supports '__thread' since version 3.3, but it supports
dnl '_Thread_local' only starting with version 4.9.