Debian Codegraph @

m4/threadlib.m4

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