On 06/13/2014 06:57 PM, Paul Eggert wrote: > On 06/13/2014 10:29 AM, Pádraig Brady wrote: >> So I'd be inclined to add those definitions in the pthread module, >> but if not we could define at the top of sort.c at least? > > The latter doesn't sound safe, since it would mean the files in > libcoreutils.a would be compiled without -D_THREAD_SAFE and would thus access > a global shared errno even when linked with sort.c. So I vote for the former.
Attached implements that. Note this doesn't change anything for projects that (indirectly) use threadlib, like coreutils for example. They're already covered in that case. thanks, Pádraig.
>From 9c42aee8fe88c4dfe6b6e60e1570aac759829b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]> Date: Fri, 13 Jun 2014 19:56:20 +0100 Subject: [PATCH] pthread: define thread safe macros on some platforms * m4/pthread.m4 (gl_PTHREAD_CHECK): When not using the threadlib module, which otherwise handles this, define macros needed for thread safe access on some platforms. --- ChangeLog | 7 +++++++ m4/pthread.m4 | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 0 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd19897..10c43d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2014-06-13 Pádraig Brady <[email protected]> + + pthread: define thread safe macros on some platforms + * m4/pthread.m4 (gl_PTHREAD_CHECK): When not using the + threadlib module, which otherwise handles this, define + macros needed for thread safe access on some platforms. + 2014-06-13 Paul Eggert <[email protected]> regex: don't be multithreaded if USE_UNLOCKED_IO. diff --git a/m4/pthread.m4 b/m4/pthread.m4 index 1ed0dd3..9288d59 100644 --- a/m4/pthread.m4 +++ b/m4/pthread.m4 @@ -88,6 +88,30 @@ AC_DEFUN([gl_PTHREAD_CHECK], fi AC_SUBST([LIB_PTHREAD]) + dnl If the threadlib module isn't selected then setup + dnl macros to enable threadsafe operation on some platforms + if test x"$gl_use_threads" = x; then + # For using <pthread.h>: + case "$host_os" in + osf*) + # On OSF/1, the compiler needs the flag -D_REENTRANT so that it + # groks <pthread.h>. cc also understands the flag -pthread, but + # we don't use it because 1. gcc-2.95 doesn't understand -pthread, + # 2. putting a flag into CPPFLAGS that has an effect on the linker + # causes the AC_LINK_IFELSE test below to succeed unexpectedly, + # leading to wrong values of LIBTHREAD and LTLIBTHREAD. + CPPFLAGS="$CPPFLAGS -D_REENTRANT" + ;; + esac + # Some systems optimize for single-threaded programs by default, and + # need special flags to disable these optimizations. For example, the + # definition of 'errno' in <errno.h>. + case "$host_os" in + aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;; + solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;; + esac + fi + AC_REQUIRE([AC_C_RESTRICT]) ]) -- 1.7.7.6
