]> Savannah Git Hosting - gnulib.git/commitdiff
thrd: Work around thrd_join bug on AIX 7.3.1.
authorBruno Haible <bruno@clisp.org>
Fri, 18 Aug 2023 20:38:04 +0000 (22:38 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 30 Aug 2023 10:15:31 +0000 (12:15 +0200)
* m4/threads_h.m4 (gl_THREADS_H): Test against AIX 7 thrd_join bug. Set
BROKEN_THRD_JOIN.
(gl_THREADS_H_DEFAULTS): Initialize BROKEN_THRD_JOIN.
* m4/thrd.m4 (gl_FUNC_THRD_JOIN): Set REPLACE_THRD_* to 1 also if
BROKEN_THRD_JOIN is 1. Define BROKEN_THRD_START_T_OR_JOIN instead of
BROKEN_THRD_START_T.
* modules/threads-h (Makefile.am): Substitute BROKEN_THRD_JOIN.
* lib/threads.in.h (rpl_thrd_t, thrd_t): Define also if BROKEN_THRD_JOIN
is 1.
* lib/thrd.c: Test BROKEN_THRD_START_T_OR_JOIN instead of
BROKEN_THRD_START_T.
* doc/posix-functions/thrd_join.texi: Update.
* doc/posix-functions/thrd_exit.texi: Likewise.

ChangeLog
doc/posix-functions/thrd_exit.texi
doc/posix-functions/thrd_join.texi
lib/thrd.c
lib/threads.in.h
m4/thrd.m4
m4/threads_h.m4
modules/threads-h

index 41dfa771774361000987b3b70bd26bde06b38e9e..3fedc6d0b340f80d9fe888135493355499de7507 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2023-08-18  Bruno Haible  <bruno@clisp.org>
 
+       thrd: Work around thrd_join bug on AIX 7.3.1.
+       * m4/threads_h.m4 (gl_THREADS_H): Test against AIX 7 thrd_join bug. Set
+       BROKEN_THRD_JOIN.
+       (gl_THREADS_H_DEFAULTS): Initialize BROKEN_THRD_JOIN.
+       * m4/thrd.m4 (gl_FUNC_THRD_JOIN): Set REPLACE_THRD_* to 1 also if
+       BROKEN_THRD_JOIN is 1. Define BROKEN_THRD_START_T_OR_JOIN instead of
+       BROKEN_THRD_START_T.
+       * modules/threads-h (Makefile.am): Substitute BROKEN_THRD_JOIN.
+       * lib/threads.in.h (rpl_thrd_t, thrd_t): Define also if BROKEN_THRD_JOIN
+       is 1.
+       * lib/thrd.c: Test BROKEN_THRD_START_T_OR_JOIN instead of
+       BROKEN_THRD_START_T.
+       * doc/posix-functions/thrd_join.texi: Update.
+       * doc/posix-functions/thrd_exit.texi: Likewise.
+
        thrd: Refactor.
        * m4/thrd.m4 (gl_FUNC_THRD_JOIN): Define BROKEN_THRD_JOIN_NULL, not
        BROKEN_THRD_JOIN. Rename gl_cv_func_thrd_join_works to
index a0e6e0983cfb3b8953056df315ec5f5f58576e43..d212ce8d502b9eece03700f2e812f4fb20519e35 100644 (file)
@@ -19,7 +19,7 @@ This function is missing on many platforms:
 glibc 2.27, macOS 11.1, FreeBSD 9.3, NetBSD 8.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.3, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
 @item
 The exit code provided to this function is discarded on some platforms:
-AIX 7.2.
+AIX 7.3.1.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 874212a99ab57f4e2399aeda55dac1b070e2b214..06c4ce9f7f2ad66dade752bcecb6534930c97402 100644 (file)
@@ -19,7 +19,7 @@ This function is missing on many platforms:
 glibc 2.27, macOS 11.1, FreeBSD 9.3, NetBSD 8.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.3, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
 @item
 This function never stores an exit code on some platforms:
-AIX 7.2.
+AIX 7.3.1.
 @item
 This function crashes when the second argument is NULL on some platforms:
 Solaris 11.4.
index 687a0920ec8dd53e364341a501c572a3aeea077b..5592249f1dcf050f3bbc156e9049e85979eb0c4e 100644 (file)
 #if HAVE_THREADS_H
 /* Provide workarounds.  */
 
-# if BROKEN_THRD_START_T
+# if BROKEN_THRD_START_T_OR_JOIN
 
 #  undef thrd_t
 
 /* AIX 7.1..7.2 defines thrd_start_t incorrectly, namely as
    'void * (*) (void *)' instead of 'int (*) (void *)'.
-   As a consequence, its thrd_join function never stores an exit code.  */
+   As a consequence, its thrd_join function never stores an exit code.
+   AIX 7.3.1 has a corrected thrd_start_t.  But the thrd_join function still
+   never stores an exit code.  */
 
 /* The Thread-Specific Storage (TSS) key that allows to access each thread's
    'struct thrd_with_exitcode *' pointer.  */
index ff5f9974246416c9c5bb66cf2c74a021ca8d08e2..8c1f6f304fb1fc6ae1267e20d24af838a6007ab7 100644 (file)
@@ -116,6 +116,8 @@ typedef pthread_t thrd_t;
 #if @BROKEN_THRD_START_T@
 /* Need to override thrd_start_t, to make thrd_create work.  */
 # define thrd_start_t rpl_thrd_start_t
+#endif
+#if @BROKEN_THRD_START_T@ || @BROKEN_THRD_JOIN@
 /* Need to override thrd_t, to make thrd_join work.  */
 struct thrd_with_exitcode
 {
index 1c0a611ae233f15bb12059636a8417f8ad088e2a..cffce1efb6b01a1e25169922550aa82e1947e0f4 100644 (file)
@@ -1,4 +1,4 @@
-# thrd.m4 serial 3
+# thrd.m4 serial 4
 dnl Copyright (C) 2019-2023 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,15 +10,15 @@ AC_DEFUN([gl_FUNC_THRD_JOIN],
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
 
   if test $ac_cv_header_threads_h = yes; then
-    if test $BROKEN_THRD_START_T = 1; then
+    if test $BROKEN_THRD_START_T = 1 || test $BROKEN_THRD_JOIN = 1; then
       REPLACE_THRD_CREATE=1
       REPLACE_THRD_CURRENT=1
       REPLACE_THRD_DETACH=1
       REPLACE_THRD_EQUAL=1
       REPLACE_THRD_EXIT=1
       REPLACE_THRD_JOIN=1
-      AC_DEFINE([BROKEN_THRD_START_T], [1],
-        [Define if the thrd_start_t type is not as described in ISO C 11.])
+      AC_DEFINE([BROKEN_THRD_START_T_OR_JOIN], [1],
+        [Define if the thrd_start_t type is not as described in ISO C 11 or if thrd_join discards the thread's exit code.])
       dnl The thrd_exit replacement relies on pthread_exit, which on AIX is in
       dnl libpthread.
       LIBSTDTHREAD="$LIBSTDTHREAD $LIBPTHREAD"
index 29fafd28862864a4d338bb9bd3a1c517328e5806..a029bc927833e0bb37740b94bf43be59ab6292c8 100644 (file)
@@ -1,4 +1,4 @@
-# threads_h.m4 serial 10.1
+# threads_h.m4 serial 10.2
 dnl Copyright (C) 2019-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -45,6 +45,46 @@ AC_DEFUN_ONCE([gl_THREADS_H],
       ])
     if test $gl_cv_thrd_start_t_correct != yes; then
       BROKEN_THRD_START_T=1
+    else
+      dnl On AIX 7.3.1, thrd_join still never stores an exit code.
+      AC_CACHE_CHECK([whether thrd_join works],
+        [gl_cv_func_thrd_join_works],
+        [save_LIBS="$LIBS"
+         LIBS="$LIBS $LIBSTDTHREAD"
+         AC_RUN_IFELSE(
+           [AC_LANG_PROGRAM(
+              [[#include <stddef.h>
+                #include <threads.h>
+                #define MAGIC 1266074729
+                static int func (void *arg)
+                {
+                  return MAGIC;
+                }
+              ]],
+              [[thrd_t thread;
+                if (thrd_create (&thread, func, NULL) != thrd_success)
+                  return 1;
+                int ret = 0xDEADBEEF;
+                if (thrd_join (thread, &ret) != thrd_success)
+                  return 2;
+                if (ret != MAGIC)
+                  return (ret == 0xDEADBEEF ? 3 : 4);
+                return 0;
+              ]])],
+           [gl_cv_func_thrd_join_works=yes],
+           [gl_cv_func_thrd_join_works=no],
+           [case "$host_os" in
+                    # Only AIX is known to be broken.
+              aix*) gl_cv_func_thrd_join_works="guessing no" ;;
+              *)    gl_cv_func_thrd_join_works="guessing yes" ;;
+            esac
+           ])
+         LIBS="$save_LIBS"
+        ])
+      case "$gl_cv_func_thrd_join_works" in
+        *yes) ;;
+        *) BROKEN_THRD_JOIN=1 ;;
+      esac
     fi
   fi
 
@@ -169,6 +209,7 @@ AC_DEFUN([gl_THREADS_H_DEFAULTS],
 [
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_THREAD_LOCAL=1;    AC_SUBST([HAVE_THREAD_LOCAL])
+  BROKEN_THRD_JOIN=0;     AC_SUBST([BROKEN_THRD_JOIN])
   BROKEN_THRD_START_T=0;  AC_SUBST([BROKEN_THRD_START_T])
   REPLACE_THRD_CREATE=0;  AC_SUBST([REPLACE_THRD_CREATE])
   REPLACE_THRD_CURRENT=0; AC_SUBST([REPLACE_THRD_CURRENT])
index 6daffd0bd0b6c7e536ff3f19591d1eafa9bcfa8b..0a1a7571374b5591597fe9c1d1e78c384a6444fb 100644 (file)
@@ -55,6 +55,7 @@ threads.h: threads.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(_NORETURN_H
              -e 's/@''GNULIB_THRD''@/$(GNULIB_THRD)/g' \
              -e 's/@''GNULIB_TSS''@/$(GNULIB_TSS)/g' \
              -e 's|@''HAVE_THREAD_LOCAL''@|$(HAVE_THREAD_LOCAL)|g' \
+             -e 's|@''BROKEN_THRD_JOIN''@|$(BROKEN_THRD_JOIN)|g' \
              -e 's|@''BROKEN_THRD_START_T''@|$(BROKEN_THRD_START_T)|g' \
              -e 's|@''REPLACE_THRD_CREATE''@|$(REPLACE_THRD_CREATE)|g' \
              -e 's|@''REPLACE_THRD_CURRENT''@|$(REPLACE_THRD_CURRENT)|g' \