threadlib.m4 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. # threadlib.m4 serial 29
  2. dnl Copyright (C) 2005-2021 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. dnl From Bruno Haible.
  7. AC_PREREQ([2.60])
  8. dnl The general structure of the multithreading modules in gnulib is that we
  9. dnl have three set of modules:
  10. dnl
  11. dnl * POSIX API:
  12. dnl pthread, which combines
  13. dnl pthread-h
  14. dnl pthread-thread
  15. dnl pthread-once
  16. dnl pthread-mutex
  17. dnl pthread-rwlock
  18. dnl pthread-cond
  19. dnl pthread-tss
  20. dnl pthread-spin
  21. dnl sched_yield
  22. dnl
  23. dnl * ISO C API:
  24. dnl threads, which combines
  25. dnl threads-h
  26. dnl thrd
  27. dnl mtx
  28. dnl cnd
  29. dnl tss
  30. dnl
  31. dnl * Gnulib API, with an implementation that can be chosen at configure
  32. dnl time through the option --enable-threads=...
  33. dnl thread
  34. dnl lock
  35. dnl cond
  36. dnl tls
  37. dnl yield
  38. dnl
  39. dnl They are independent, except for the fact that
  40. dnl - the implementation of the ISO C API may use the POSIX (or some other
  41. dnl platform dependent) API,
  42. dnl - the implementation of the Gnulib API may use the POSIX or ISO C or
  43. dnl some other platform dependent API, depending on the --enable-threads
  44. dnl option.
  45. dnl
  46. dnl This file contains macros for all of these APIs!
  47. dnl ============================================================================
  48. dnl Macros for all thread APIs
  49. AC_DEFUN([gl_ANYTHREADLIB_EARLY],
  50. [
  51. AC_REQUIRE([AC_CANONICAL_HOST])
  52. if test -z "$gl_anythreadlib_early_done"; then
  53. case "$host_os" in
  54. osf*)
  55. # On OSF/1, the compiler needs the flag -D_REENTRANT so that it
  56. # groks <pthread.h>. cc also understands the flag -pthread, but
  57. # we don't use it because 1. gcc-2.95 doesn't understand -pthread,
  58. # 2. putting a flag into CPPFLAGS that has an effect on the linker
  59. # causes the AC_LINK_IFELSE test below to succeed unexpectedly,
  60. # leading to wrong values of LIBTHREAD and LTLIBTHREAD.
  61. CPPFLAGS="$CPPFLAGS -D_REENTRANT"
  62. ;;
  63. esac
  64. # Some systems optimize for single-threaded programs by default, and
  65. # need special flags to disable these optimizations. For example, the
  66. # definition of 'errno' in <errno.h>.
  67. case "$host_os" in
  68. aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;;
  69. solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;;
  70. esac
  71. gl_anythreadlib_early_done=done
  72. fi
  73. ])
  74. dnl Checks whether the compiler and linker support weak declarations of symbols.
  75. AC_DEFUN([gl_WEAK_SYMBOLS],
  76. [
  77. AC_REQUIRE([AC_CANONICAL_HOST])
  78. AC_CACHE_CHECK([whether imported symbols can be declared weak],
  79. [gl_cv_have_weak],
  80. [gl_cv_have_weak=no
  81. dnl First, test whether the compiler accepts it syntactically.
  82. AC_LINK_IFELSE(
  83. [AC_LANG_PROGRAM(
  84. [[extern void xyzzy ();
  85. #pragma weak xyzzy]],
  86. [[xyzzy();]])],
  87. [gl_cv_have_weak=maybe])
  88. if test $gl_cv_have_weak = maybe; then
  89. dnl Second, test whether it actually works. On Cygwin 1.7.2, with
  90. dnl gcc 4.3, symbols declared weak always evaluate to the address 0.
  91. AC_RUN_IFELSE(
  92. [AC_LANG_SOURCE([[
  93. #include <stdio.h>
  94. #pragma weak fputs
  95. int main ()
  96. {
  97. return (fputs == NULL);
  98. }]])],
  99. [gl_cv_have_weak=yes],
  100. [gl_cv_have_weak=no],
  101. [dnl When cross-compiling, assume that only ELF platforms support
  102. dnl weak symbols.
  103. AC_EGREP_CPP([Extensible Linking Format],
  104. [#ifdef __ELF__
  105. Extensible Linking Format
  106. #endif
  107. ],
  108. [gl_cv_have_weak="guessing yes"],
  109. [gl_cv_have_weak="guessing no"])
  110. ])
  111. fi
  112. dnl But when linking statically, weak symbols don't work.
  113. case " $LDFLAGS " in
  114. *" -static "*) gl_cv_have_weak=no ;;
  115. esac
  116. dnl Test for a bug in FreeBSD 11: A link error occurs when using a weak
  117. dnl symbol and linking against a shared library that has a dependency on
  118. dnl the shared library that defines the symbol.
  119. case "$gl_cv_have_weak" in
  120. *yes)
  121. case "$host_os" in
  122. freebsd* | dragonfly*)
  123. : > conftest1.c
  124. $CC $CPPFLAGS $CFLAGS $LDFLAGS -fPIC -shared -o libempty.so conftest1.c -lpthread >&AS_MESSAGE_LOG_FD 2>&1
  125. cat <<EOF > conftest2.c
  126. #include <pthread.h>
  127. #pragma weak pthread_mutexattr_gettype
  128. int main ()
  129. {
  130. return (pthread_mutexattr_gettype != NULL);
  131. }
  132. EOF
  133. $CC $CPPFLAGS $CFLAGS $LDFLAGS -o conftest conftest2.c libempty.so >&AS_MESSAGE_LOG_FD 2>&1 \
  134. || gl_cv_have_weak=no
  135. rm -f conftest1.c libempty.so conftest2.c conftest
  136. ;;
  137. esac
  138. ;;
  139. esac
  140. ])
  141. case "$gl_cv_have_weak" in
  142. *yes)
  143. AC_DEFINE([HAVE_WEAK_SYMBOLS], [1],
  144. [Define to 1 if the compiler and linker support weak declarations of symbols.])
  145. ;;
  146. esac
  147. ])
  148. dnl ============================================================================
  149. dnl Macros for the POSIX API
  150. dnl gl_PTHREADLIB
  151. dnl -------------
  152. dnl Tests for the libraries needs for using the POSIX threads API.
  153. dnl Sets the variable LIBPTHREAD to the linker options for use in a Makefile.
  154. dnl Sets the variable LIBPMULTITHREAD, for programs that really need
  155. dnl multithread functionality. The difference between LIBPTHREAD and
  156. dnl LIBPMULTITHREAD is that on platforms supporting weak symbols, typically
  157. dnl LIBPTHREAD is empty whereas LIBPMULTITHREAD is not.
  158. dnl Sets the variable LIB_SCHED_YIELD to the linker options needed to use the
  159. dnl sched_yield() function.
  160. dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
  161. dnl multithread-safe programs.
  162. dnl Defines the C macro HAVE_PTHREAD_API if (at least parts of) the POSIX
  163. dnl threads API is available.
  164. dnl The guts of gl_PTHREADLIB. Needs to be expanded only once.
  165. AC_DEFUN([gl_PTHREADLIB_BODY],
  166. [
  167. AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
  168. if test -z "$gl_pthreadlib_body_done"; then
  169. gl_pthread_api=no
  170. LIBPTHREAD=
  171. LIBPMULTITHREAD=
  172. # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that
  173. # it groks <pthread.h>. It's added above, in gl_ANYTHREADLIB_EARLY.
  174. AC_CHECK_HEADER([pthread.h],
  175. [gl_have_pthread_h=yes], [gl_have_pthread_h=no])
  176. if test "$gl_have_pthread_h" = yes; then
  177. # Other possible tests:
  178. # -lpthreads (FSU threads, PCthreads)
  179. # -lgthreads
  180. # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist
  181. # in libc. IRIX 6.5 has the first one in both libc and libpthread, but
  182. # the second one only in libpthread, and lock.c needs it.
  183. #
  184. # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04
  185. # needs -pthread for some reason. See:
  186. # https://lists.gnu.org/r/bug-gnulib/2014-09/msg00023.html
  187. save_LIBS=$LIBS
  188. for gl_pthread in '' '-pthread'; do
  189. LIBS="$LIBS $gl_pthread"
  190. AC_LINK_IFELSE(
  191. [AC_LANG_PROGRAM(
  192. [[#include <pthread.h>
  193. pthread_mutex_t m;
  194. pthread_mutexattr_t ma;
  195. ]],
  196. [[pthread_mutex_lock (&m);
  197. pthread_mutexattr_init (&ma);]])],
  198. [gl_pthread_api=yes
  199. LIBPTHREAD=$gl_pthread
  200. LIBPMULTITHREAD=$gl_pthread])
  201. LIBS=$save_LIBS
  202. test $gl_pthread_api = yes && break
  203. done
  204. # Test for libpthread by looking for pthread_kill. (Not pthread_self,
  205. # since it is defined as a macro on OSF/1.)
  206. if test $gl_pthread_api = yes && test -z "$LIBPTHREAD"; then
  207. # The program links fine without libpthread. But it may actually
  208. # need to link with libpthread in order to create multiple threads.
  209. AC_CHECK_LIB([pthread], [pthread_kill],
  210. [LIBPMULTITHREAD=-lpthread
  211. # On Solaris and HP-UX, most pthread functions exist also in libc.
  212. # Therefore pthread_in_use() needs to actually try to create a
  213. # thread: pthread_create from libc will fail, whereas
  214. # pthread_create will actually create a thread.
  215. # On Solaris 10 or newer, this test is no longer needed, because
  216. # libc contains the fully functional pthread functions.
  217. case "$host_os" in
  218. solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*)
  219. AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
  220. [Define if the pthread_in_use() detection is hard.])
  221. esac
  222. ])
  223. elif test $gl_pthread_api != yes; then
  224. # Some library is needed. Try libpthread and libc_r.
  225. AC_CHECK_LIB([pthread], [pthread_kill],
  226. [gl_pthread_api=yes
  227. LIBPTHREAD=-lpthread
  228. LIBPMULTITHREAD=-lpthread])
  229. if test $gl_pthread_api != yes; then
  230. # For FreeBSD 4.
  231. AC_CHECK_LIB([c_r], [pthread_kill],
  232. [gl_pthread_api=yes
  233. LIBPTHREAD=-lc_r
  234. LIBPMULTITHREAD=-lc_r])
  235. fi
  236. fi
  237. fi
  238. AC_MSG_CHECKING([whether POSIX threads API is available])
  239. AC_MSG_RESULT([$gl_pthread_api])
  240. AC_SUBST([LIBPTHREAD])
  241. AC_SUBST([LIBPMULTITHREAD])
  242. if test $gl_pthread_api = yes; then
  243. AC_DEFINE([HAVE_PTHREAD_API], [1],
  244. [Define if you have the <pthread.h> header and the POSIX threads API.])
  245. fi
  246. dnl On some systems, sched_yield is in librt, rather than in libpthread.
  247. AC_LINK_IFELSE(
  248. [AC_LANG_PROGRAM(
  249. [[#include <sched.h>]],
  250. [[sched_yield ();]])],
  251. [LIB_SCHED_YIELD=
  252. ],
  253. [dnl Solaris 7...10 has sched_yield in librt, not in libpthread or libc.
  254. AC_CHECK_LIB([rt], [sched_yield], [LIB_SCHED_YIELD=-lrt],
  255. [dnl Solaris 2.5.1, 2.6 has sched_yield in libposix4, not librt.
  256. AC_CHECK_LIB([posix4], [sched_yield], [LIB_SCHED_YIELD=-lposix4])])
  257. ])
  258. AC_SUBST([LIB_SCHED_YIELD])
  259. gl_pthreadlib_body_done=done
  260. fi
  261. ])
  262. AC_DEFUN([gl_PTHREADLIB],
  263. [
  264. AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
  265. gl_PTHREADLIB_BODY
  266. ])
  267. dnl ============================================================================
  268. dnl Macros for the ISO C API
  269. dnl gl_STDTHREADLIB
  270. dnl ---------------
  271. dnl Tests for the libraries needs for using the ISO C threads API.
  272. dnl Sets the variable LIBSTDTHREAD to the linker options for use in a Makefile.
  273. dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
  274. dnl multithread-safe programs.
  275. dnl Defines the C macro HAVE_THREADS_H if (at least parts of) the ISO C threads
  276. dnl API is available.
  277. dnl The guts of gl_STDTHREADLIB. Needs to be expanded only once.
  278. AC_DEFUN([gl_STDTHREADLIB_BODY],
  279. [
  280. AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
  281. AC_REQUIRE([AC_CANONICAL_HOST])
  282. if test -z "$gl_stdthreadlib_body_done"; then
  283. AC_CHECK_HEADERS_ONCE([threads.h])
  284. case "$host_os" in
  285. mingw*)
  286. LIBSTDTHREAD=
  287. ;;
  288. *)
  289. gl_PTHREADLIB_BODY
  290. if test $ac_cv_header_threads_h = yes; then
  291. dnl glibc >= 2.29 has thrd_create in libpthread.
  292. dnl FreeBSD >= 10 has thrd_create in libstdthreads; this library depends
  293. dnl on libpthread (for the symbol 'pthread_mutexattr_gettype').
  294. dnl AIX >= 7.1 and Solaris >= 11.4 have thrd_create in libc.
  295. AC_CHECK_FUNCS([thrd_create])
  296. if test $ac_cv_func_thrd_create = yes; then
  297. LIBSTDTHREAD=
  298. else
  299. AC_CHECK_LIB([stdthreads], [thrd_create], [
  300. LIBSTDTHREAD='-lstdthreads -lpthread'
  301. ], [
  302. dnl Guess that thrd_create is in libpthread.
  303. LIBSTDTHREAD="$LIBPMULTITHREAD"
  304. ])
  305. fi
  306. else
  307. dnl Libraries needed by thrd.c, mtx.c, cnd.c, tss.c.
  308. LIBSTDTHREAD="$LIBPMULTITHREAD $LIB_SCHED_YIELD"
  309. fi
  310. ;;
  311. esac
  312. AC_SUBST([LIBSTDTHREAD])
  313. AC_MSG_CHECKING([whether ISO C threads API is available])
  314. AC_MSG_RESULT([$ac_cv_header_threads_h])
  315. gl_stdthreadlib_body_done=done
  316. fi
  317. ])
  318. AC_DEFUN([gl_STDTHREADLIB],
  319. [
  320. AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
  321. gl_STDTHREADLIB_BODY
  322. ])
  323. dnl ============================================================================
  324. dnl Macros for the Gnulib API
  325. dnl gl_THREADLIB
  326. dnl ------------
  327. dnl Tests for a multithreading library to be used.
  328. dnl If the configure.ac contains a definition of the gl_THREADLIB_DEFAULT_NO
  329. dnl (it must be placed before the invocation of gl_THREADLIB_EARLY!), then the
  330. dnl default is 'no', otherwise it is system dependent. In both cases, the user
  331. dnl can change the choice through the options --enable-threads=choice or
  332. dnl --disable-threads.
  333. dnl Defines at most one of the macros USE_ISOC_THREADS, USE_POSIX_THREADS,
  334. dnl USE_ISOC_AND_POSIX_THREADS, USE_WINDOWS_THREADS.
  335. dnl The choice --enable-threads=isoc+posix is available only on platforms that
  336. dnl have both the ISO C and the POSIX threads APIs. It has the effect of using
  337. dnl the ISO C API for most things and the POSIX API only for creating and
  338. dnl controlling threads (because there is no equivalent to pthread_atfork in
  339. dnl the ISO C API).
  340. dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use
  341. dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with
  342. dnl libtool).
  343. dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for
  344. dnl programs that really need multithread functionality. The difference
  345. dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak
  346. dnl symbols, typically LIBTHREAD is empty whereas LIBMULTITHREAD is not.
  347. dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
  348. dnl multithread-safe programs.
  349. dnl Since support for GNU pth was removed, $LTLIBTHREAD and $LIBTHREAD have the
  350. dnl same value, and similarly $LTLIBMULTITHREAD and $LIBMULTITHREAD have the
  351. dnl same value. Only system libraries are needed.
  352. AC_DEFUN([gl_THREADLIB_EARLY],
  353. [
  354. AC_REQUIRE([gl_THREADLIB_EARLY_BODY])
  355. ])
  356. dnl The guts of gl_THREADLIB_EARLY. Needs to be expanded only once.
  357. AC_DEFUN([gl_THREADLIB_EARLY_BODY],
  358. [
  359. dnl Ordering constraints: This macro modifies CPPFLAGS in a way that
  360. dnl influences the result of the autoconf tests that test for *_unlocked
  361. dnl declarations, on AIX 5 at least. Therefore it must come early.
  362. AC_BEFORE([$0], [gl_FUNC_GLIBC_UNLOCKED_IO])dnl
  363. AC_BEFORE([$0], [gl_ARGP])dnl
  364. AC_REQUIRE([AC_CANONICAL_HOST])
  365. dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems.
  366. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  367. dnl Check for multithreading.
  368. m4_ifdef([gl_THREADLIB_DEFAULT_NO],
  369. [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])],
  370. [m4_divert_text([DEFAULTS], [gl_use_threads_default=])])
  371. m4_divert_text([DEFAULTS], [gl_use_winpthreads_default=])
  372. AC_ARG_ENABLE([threads],
  373. AS_HELP_STRING([--enable-threads={isoc|posix|isoc+posix|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [
  374. AS_HELP_STRING([--disable-threads], [build without multithread safety])]),
  375. [gl_use_threads=$enableval],
  376. [if test -n "$gl_use_threads_default"; then
  377. gl_use_threads="$gl_use_threads_default"
  378. else
  379. changequote(,)dnl
  380. case "$host_os" in
  381. dnl Disable multithreading by default on OSF/1, because it interferes
  382. dnl with fork()/exec(): When msgexec is linked with -lpthread, its
  383. dnl child process gets an endless segmentation fault inside execvp().
  384. osf*) gl_use_threads=no ;;
  385. dnl Disable multithreading by default on Cygwin 1.5.x, because it has
  386. dnl bugs that lead to endless loops or crashes. See
  387. dnl <https://cygwin.com/ml/cygwin/2009-08/msg00283.html>.
  388. cygwin*)
  389. case `uname -r` in
  390. 1.[0-5].*) gl_use_threads=no ;;
  391. *) gl_use_threads=yes ;;
  392. esac
  393. ;;
  394. dnl Obey gl_AVOID_WINPTHREAD on mingw.
  395. mingw*)
  396. case "$gl_use_winpthreads_default" in
  397. yes) gl_use_threads=posix ;;
  398. no) gl_use_threads=windows ;;
  399. *) gl_use_threads=yes ;;
  400. esac
  401. ;;
  402. *) gl_use_threads=yes ;;
  403. esac
  404. changequote([,])dnl
  405. fi
  406. ])
  407. if test "$gl_use_threads" = yes \
  408. || test "$gl_use_threads" = isoc \
  409. || test "$gl_use_threads" = posix \
  410. || test "$gl_use_threads" = isoc+posix; then
  411. # For using <threads.h> or <pthread.h>:
  412. gl_ANYTHREADLIB_EARLY
  413. fi
  414. ])
  415. dnl The guts of gl_THREADLIB. Needs to be expanded only once.
  416. AC_DEFUN([gl_THREADLIB_BODY],
  417. [
  418. AC_REQUIRE([gl_THREADLIB_EARLY_BODY])
  419. gl_threads_api=none
  420. LIBTHREAD=
  421. LTLIBTHREAD=
  422. LIBMULTITHREAD=
  423. LTLIBMULTITHREAD=
  424. if test "$gl_use_threads" != no; then
  425. dnl Check whether the compiler and linker support weak declarations.
  426. gl_WEAK_SYMBOLS
  427. if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
  428. dnl If we use weak symbols to implement pthread_in_use / pth_in_use /
  429. dnl thread_in_use, we also need to test whether the ISO C 11 thrd_create
  430. dnl facility is in use.
  431. AC_CHECK_HEADERS_ONCE([threads.h])
  432. :
  433. fi
  434. if test "$gl_use_threads" = isoc || test "$gl_use_threads" = isoc+posix; then
  435. AC_CHECK_HEADERS_ONCE([threads.h])
  436. gl_have_isoc_threads="$ac_cv_header_threads_h"
  437. fi
  438. if test "$gl_use_threads" = yes \
  439. || test "$gl_use_threads" = posix \
  440. || test "$gl_use_threads" = isoc+posix; then
  441. gl_PTHREADLIB_BODY
  442. LIBTHREAD=$LIBPTHREAD LTLIBTHREAD=$LIBPTHREAD
  443. LIBMULTITHREAD=$LIBPMULTITHREAD LTLIBMULTITHREAD=$LIBPMULTITHREAD
  444. if test $gl_pthread_api = yes; then
  445. if test "$gl_use_threads" = isoc+posix && test "$gl_have_isoc_threads" = yes; then
  446. gl_threads_api='isoc+posix'
  447. AC_DEFINE([USE_ISOC_AND_POSIX_THREADS], [1],
  448. [Define if the combination of the ISO C and POSIX multithreading APIs can be used.])
  449. LIBTHREAD= LTLIBTHREAD=
  450. else
  451. gl_threads_api=posix
  452. AC_DEFINE([USE_POSIX_THREADS], [1],
  453. [Define if the POSIX multithreading library can be used.])
  454. if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then
  455. if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
  456. AC_DEFINE([USE_POSIX_THREADS_WEAK], [1],
  457. [Define if references to the POSIX multithreading library should be made weak.])
  458. LIBTHREAD= LTLIBTHREAD=
  459. else
  460. case "$host_os" in
  461. freebsd* | dragonfly*)
  462. if test "x$LIBTHREAD" != "x$LIBMULTITHREAD"; then
  463. dnl If weak symbols can't tell whether pthread_create(), pthread_key_create()
  464. dnl etc. will succeed, we need a runtime test.
  465. AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
  466. [Define if the pthread_in_use() detection is hard.])
  467. fi
  468. ;;
  469. esac
  470. fi
  471. fi
  472. fi
  473. fi
  474. fi
  475. if test $gl_threads_api = none; then
  476. if test "$gl_use_threads" = isoc && test "$gl_have_isoc_threads" = yes; then
  477. gl_STDTHREADLIB_BODY
  478. LIBTHREAD=$LIBSTDTHREAD LTLIBTHREAD=$LIBSTDTHREAD
  479. LIBMULTITHREAD=$LIBSTDTHREAD LTLIBMULTITHREAD=$LIBSTDTHREAD
  480. gl_threads_api=isoc
  481. AC_DEFINE([USE_ISOC_THREADS], [1],
  482. [Define if the ISO C multithreading library can be used.])
  483. fi
  484. fi
  485. if test $gl_threads_api = none; then
  486. case "$gl_use_threads" in
  487. yes | windows | win32) # The 'win32' is for backward compatibility.
  488. if { case "$host_os" in
  489. mingw*) true;;
  490. *) false;;
  491. esac
  492. }; then
  493. gl_threads_api=windows
  494. AC_DEFINE([USE_WINDOWS_THREADS], [1],
  495. [Define if the native Windows multithreading API can be used.])
  496. fi
  497. ;;
  498. esac
  499. fi
  500. fi
  501. AC_MSG_CHECKING([for multithread API to use])
  502. AC_MSG_RESULT([$gl_threads_api])
  503. AC_SUBST([LIBTHREAD])
  504. AC_SUBST([LTLIBTHREAD])
  505. AC_SUBST([LIBMULTITHREAD])
  506. AC_SUBST([LTLIBMULTITHREAD])
  507. ])
  508. AC_DEFUN([gl_THREADLIB],
  509. [
  510. AC_REQUIRE([gl_THREADLIB_EARLY])
  511. AC_REQUIRE([gl_THREADLIB_BODY])
  512. ])
  513. dnl gl_DISABLE_THREADS
  514. dnl ------------------
  515. dnl Sets the gl_THREADLIB default so that threads are not used by default.
  516. dnl The user can still override it at installation time, by using the
  517. dnl configure option '--enable-threads'.
  518. AC_DEFUN([gl_DISABLE_THREADS], [
  519. m4_divert_text([INIT_PREPARE], [gl_use_threads_default=no])
  520. ])
  521. dnl gl_AVOID_WINPTHREAD
  522. dnl -------------------
  523. dnl Sets the gl_THREADLIB default so that on mingw, a dependency to the
  524. dnl libwinpthread DLL (mingw-w64 winpthreads library) is avoided.
  525. dnl The user can still override it at installation time, by using the
  526. dnl configure option '--enable-threads'.
  527. AC_DEFUN([gl_AVOID_WINPTHREAD], [
  528. m4_divert_text([INIT_PREPARE], [gl_use_winpthreads_default=no])
  529. ])
  530. dnl ============================================================================
  531. dnl Survey of platforms:
  532. dnl
  533. dnl Platform Available Compiler Supports test-lock
  534. dnl flavours option weak result
  535. dnl --------------- --------- --------- -------- ---------
  536. dnl Linux 2.4/glibc posix -lpthread Y OK
  537. dnl
  538. dnl GNU Hurd/glibc posix
  539. dnl
  540. dnl Ubuntu 14.04 posix -pthread Y OK
  541. dnl
  542. dnl FreeBSD 5.3 posix -lc_r Y
  543. dnl posix -lkse ? Y
  544. dnl posix -lpthread ? Y
  545. dnl posix -lthr Y
  546. dnl
  547. dnl FreeBSD 5.2 posix -lc_r Y
  548. dnl posix -lkse Y
  549. dnl posix -lthr Y
  550. dnl
  551. dnl FreeBSD 4.0,4.10 posix -lc_r Y OK
  552. dnl
  553. dnl NetBSD 1.6 --
  554. dnl
  555. dnl OpenBSD 3.4 posix -lpthread Y OK
  556. dnl
  557. dnl Mac OS X 10.[123] posix -lpthread Y OK
  558. dnl
  559. dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK
  560. dnl
  561. dnl HP-UX 11 posix -lpthread N (cc) OK
  562. dnl Y (gcc)
  563. dnl
  564. dnl IRIX 6.5 posix -lpthread Y 0.5
  565. dnl
  566. dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK
  567. dnl
  568. dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK
  569. dnl -lpthread (gcc) Y
  570. dnl
  571. dnl Cygwin posix -lpthread Y OK
  572. dnl
  573. dnl Mingw windows N OK
  574. dnl
  575. dnl BeOS 5 --
  576. dnl
  577. dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is
  578. dnl turned off:
  579. dnl OK if all three tests terminate OK,
  580. dnl 0.5 if the first test terminates OK but the second one loops endlessly,
  581. dnl 0.0 if the first test already loops endlessly.