immutable: Add tests.
[gnulib.git] / m4 / thrd.m4
blob004d9b34c35490db03e531da062396f0aeec0f47
1 # thrd.m4 serial 1
2 dnl Copyright (C) 2019-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.
7 AC_DEFUN([gl_FUNC_THRD_JOIN],
9   AC_REQUIRE([gl_THREADS_H])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12   if test $ac_cv_header_threads_h = yes; then
13     if test $BROKEN_THRD_START_T = 1; then
14       REPLACE_THRD_CREATE=1
15       REPLACE_THRD_CURRENT=1
16       REPLACE_THRD_DETACH=1
17       REPLACE_THRD_EQUAL=1
18       REPLACE_THRD_JOIN=1
19       AC_DEFINE([BROKEN_THRD_START_T], [1],
20         [Define if the thrd_start_t type is not as described in ISO C 11.])
21     fi
23     dnl On Solaris 11.4, thrd_join crashes when the second argument is NULL.
24     AC_CACHE_CHECK([whether thrd_join works],
25       [gl_cv_func_thrd_join_works],
26       [save_LIBS="$LIBS"
27        LIBS="$LIBS $LIBSTDTHREAD"
28        AC_RUN_IFELSE(
29          [AC_LANG_PROGRAM(
30             [[#include <stddef.h>
31               #include <threads.h>
32               static int func (void *arg)
33               {
34                 return (arg != NULL);
35               }
36             ]],
37             [[thrd_t thread;
38               if (thrd_create (&thread, func, NULL) != thrd_success)
39                 return 1;
40               if (thrd_join (thread, NULL) != thrd_success)
41                 return 2;
42               return 0;
43             ]])],
44          [gl_cv_func_thrd_join_works=yes],
45          [gl_cv_func_thrd_join_works=no],
46          [case "$host_os" in
47                       # Only Solaris is known to be broken.
48             solaris*) gl_cv_func_thrd_join_works="guessing no" ;;
49             *)        gl_cv_func_thrd_join_works="guessing yes" ;;
50           esac
51          ])
52        LIBS="$save_LIBS"
53       ])
54     case "$gl_cv_func_thrd_join_works" in
55       *yes) ;;
56       *)
57         REPLACE_THRD_JOIN=1
58         AC_DEFINE([BROKEN_THRD_JOIN], [1],
59           [Define if the thrd_join function does not behave as in ISO C 11.])
60         ;;
61     esac
62   fi