From: Bruno Haible Date: Fri, 18 Aug 2023 18:52:08 +0000 (+0200) Subject: thrd: On AIX 7.1 and 7.2, override also thrd_exit. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=0fea5abdd128ded15898762dd00b38cbb3ab0a1d;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 4aa72e1c06..e66035ca8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2023-08-18 Bruno Haible + + 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 aligned_alloc: Fix test failure on AIX 7.3 with ibm-clang. diff --git a/doc/posix-functions/thrd_exit.texi b/doc/posix-functions/thrd_exit.texi index e1af16e428..a0e6e0983c 100644 --- a/doc/posix-functions/thrd_exit.texi +++ b/doc/posix-functions/thrd_exit.texi @@ -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: diff --git a/lib/thrd.c b/lib/thrd.c index 5e9a988c2c..9abea10a2c 100644 --- a/lib/thrd.c +++ b/lib/thrd.c @@ -203,6 +203,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 diff --git a/lib/threads.in.h b/lib/threads.in.h index ac87ade571..6d1769cc53 100644 --- a/lib/threads.in.h +++ b/lib/threads.in.h @@ -298,11 +298,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 diff --git a/m4/thrd.m4 b/m4/thrd.m4 index 452629dbbb..fed111695f 100644 --- a/m4/thrd.m4 +++ b/m4/thrd.m4 @@ -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. diff --git a/m4/threads_h.m4 b/m4/threads_h.m4 index 851490c123..f74c146173 100644 --- a/m4/threads_h.m4 +++ b/m4/threads_h.m4 @@ -1,4 +1,4 @@ -# threads_h.m4 serial 11 +# threads_h.m4 serial 12 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, @@ -175,5 +175,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]) ]) diff --git a/modules/threads-h b/modules/threads-h index 1a2b83a354..2056df01f0 100644 --- a/modules/threads-h +++ b/modules/threads-h @@ -61,6 +61,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)' \