]> Savannah Git Hosting - gnulib.git/commitdiff
thrd: On AIX 7.1 and 7.2, override also thrd_exit.
authorBruno Haible <bruno@clisp.org>
Fri, 18 Aug 2023 18:52:08 +0000 (20:52 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 30 Aug 2023 10:13:56 +0000 (12:13 +0200)
* lib/threads.in.h (thrd_exit): Consider REPLACE_THRD_EXIT.
* lib/thrd.c (rpl_thrd_exit): New function.
* m4/threads_h.m4 (gl_THREADS_H_DEFAULTS): Initialize REPLACE_THRD_EXIT.
* m4/thrd.m4 (gl_FUNC_THRD_JOIN): Set also REPLACE_THRD_EXIT and adjust
LIBSTDTHREAD.
* modules/threads-h (Makefile.am): Substitute REPLACE_THRD_EXIT.
* doc/posix-functions/thrd_exit.texi: Mention the AIX thrd_join problem
also here.

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

index 8eba0282caf74720e107b7b9fd5f1f38833dcf52..661dd10869c323397904a987393b4cd64861a07a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2023-08-18  Bruno Haible  <bruno@clisp.org>
+
+       thrd: On AIX 7.1 and 7.2, override also thrd_exit.
+       * lib/threads.in.h (thrd_exit): Consider REPLACE_THRD_EXIT.
+       * lib/thrd.c (rpl_thrd_exit): New function.
+       * m4/threads_h.m4 (gl_THREADS_H_DEFAULTS): Initialize REPLACE_THRD_EXIT.
+       * m4/thrd.m4 (gl_FUNC_THRD_JOIN): Set also REPLACE_THRD_EXIT and adjust
+       LIBSTDTHREAD.
+       * modules/threads-h (Makefile.am): Substitute REPLACE_THRD_EXIT.
+       * doc/posix-functions/thrd_exit.texi: Mention the AIX thrd_join problem
+       also here.
+
 2023-08-18  Bruno Haible  <bruno@clisp.org>
 
        aligned_alloc: Fix test failure on AIX 7.3 with ibm-clang.
index e1af16e4288d34e58062006796841ec36990ff52..a0e6e0983cfb3b8953056df315ec5f5f58576e43 100644 (file)
@@ -17,6 +17,9 @@ Portability problems fixed by Gnulib:
 @item
 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.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index bb0e10fc8bf68163405d88eabbabdfba334e4cb4..36117bb6de43f3642fbc0727e728ea1978dac6fb 100644 (file)
@@ -201,6 +201,21 @@ rpl_thrd_join (rpl_thrd_t thread, int *exitcodep)
   }
 }
 
+_Noreturn void
+rpl_thrd_exit (int exitcode)
+{
+  rpl_thrd_t t = rpl_thrd_current ();
+
+  /* Store the exitcode, for use by thrd_join().  */
+  t->exitcode = exitcode;
+  if (t->detached)
+    {
+      /* Clean up the thread, like thrd_join would do.  */
+      free (t);
+    }
+  pthread_exit (NULL);
+}
+
 # endif
 
 # if BROKEN_THRD_JOIN
index aa15e34e25249f82af2c736257c235b61cf160ee..ff5f9974246416c9c5bb66cf2c74a021ca8d08e2 100644 (file)
@@ -275,11 +275,19 @@ _GL_WARN_ON_USE (thrd_join, "thrd_join is unportable - "
 #endif
 
 #if @GNULIB_THRD@
-# if !@HAVE_THREADS_H@
+# if @REPLACE_THRD_EXIT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define thrd_exit rpl_thrd_exit
+#  endif
+_GL_FUNCDECL_RPL (thrd_exit, _Noreturn void, (int));
+_GL_CXXALIAS_RPL (thrd_exit, void, (int));
+# else
+#  if !@HAVE_THREADS_H@
 _GL_FUNCDECL_SYS (thrd_exit, _Noreturn void, (int));
-# endif
+#  endif
 /* Need to cast because of AIX with xlclang++.  */
 _GL_CXXALIAS_SYS_CAST (thrd_exit, void, (int));
+# endif
 _GL_CXXALIASWARN (thrd_exit);
 #elif defined GNULIB_POSIXCHECK
 # undef thrd_exit
index 452629dbbb25f47e79e46b5142c139c37eee0a98..fed111695fa3a1ba15ebc06011766c7399a50d39 100644 (file)
@@ -1,4 +1,4 @@
-# thrd.m4 serial 1
+# thrd.m4 serial 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,
@@ -15,9 +15,13 @@ AC_DEFUN([gl_FUNC_THRD_JOIN],
       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.])
+      dnl The thrd_exit replacement relies on pthread_exit, which on AIX is in
+      dnl libpthread.
+      LIBSTDTHREAD="$LIBSTDTHREAD $LIBPTHREAD"
     fi
 
     dnl On Solaris 11.4, thrd_join crashes when the second argument is NULL.
index 77fe20d279eeae4108cc75cb4a2baec036480245..29fafd28862864a4d338bb9bd3a1c517328e5806 100644 (file)
@@ -1,4 +1,4 @@
-# threads_h.m4 serial 10
+# threads_h.m4 serial 10.1
 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,
@@ -174,5 +174,6 @@ AC_DEFUN([gl_THREADS_H_DEFAULTS],
   REPLACE_THRD_CURRENT=0; AC_SUBST([REPLACE_THRD_CURRENT])
   REPLACE_THRD_DETACH=0;  AC_SUBST([REPLACE_THRD_DETACH])
   REPLACE_THRD_EQUAL=0;   AC_SUBST([REPLACE_THRD_EQUAL])
+  REPLACE_THRD_EXIT=0;    AC_SUBST([REPLACE_THRD_EXIT])
   REPLACE_THRD_JOIN=0;    AC_SUBST([REPLACE_THRD_JOIN])
 ])
index e35a5e265bd20c58eeee16de8b11c3183f0ce4a9..6daffd0bd0b6c7e536ff3f19591d1eafa9bcfa8b 100644 (file)
@@ -60,6 +60,7 @@ threads.h: threads.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(_NORETURN_H
              -e 's|@''REPLACE_THRD_CURRENT''@|$(REPLACE_THRD_CURRENT)|g' \
              -e 's|@''REPLACE_THRD_DETACH''@|$(REPLACE_THRD_DETACH)|g' \
              -e 's|@''REPLACE_THRD_EQUAL''@|$(REPLACE_THRD_EQUAL)|g' \
+             -e 's|@''REPLACE_THRD_EXIT''@|$(REPLACE_THRD_EXIT)|g' \
              -e 's|@''REPLACE_THRD_JOIN''@|$(REPLACE_THRD_JOIN)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _Noreturn/r $(_NORETURN_H)' \