Subject: bug#17773: AIX build errors with coreutils-8.22

From: Paul Eggert <[email-masked]>
Date: Fri, 13 Jun 2014 08:48:01 -0700

Pádraig Brady wrote:

> threading primitives will be used in the regex replacement _if_
> your package is using threads, i.e. has referenced the threadlib gnulib module.

Unfortunately regex also uses threads if the pthread module is used, and 
that's the problem here.  Some coreutils commands ('sort') use threads 
and others don't, but the commands that use threads are careful to not 
invoke anything like stdio or regex in an area where it wouldn't be 
thread-safe.  So I installed the attached hack instead: it abuses 
unlocked-io to mean "unlocked everything" but seemed simpler than 
anything else I could think of.  It fixes the reported problem on AIX 
anyway.

> Paul I see in the threadlib module, the addition of _REENTRANT
> or _THREAD_SAFE defines on some platforms.
> Should we be doing that also in the pthread module?

We do have a problem here.  Won't defining _THREAD_SAFE run into 
problems when combined with unlocked-io on AIX?

To be honest, the unlocked-io stuff seems so quaint now.  How much does 
it really help performance?  Perhaps we should retire it, or turn it 
into a no-op?
From a8ba7140ace794a511f97ab7de1addc6a3cf4fca Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Fri, 13 Jun 2014 08:30:48 -0700
Subject: [PATCH] regex: don't be multithreaded if USE_UNLOCKED_IO.

Problem reported by Michael Felt in: http://bugs.gnu.org/17773
* lib/regex_internal.h: Do not use multithreaded version if
USE_UNLOCKED_IO is defined.  This is a hack, but it works
around a porting bug with coreutils 8.22 on AIX 7.1.
---
 ChangeLog            | 8 ++++++++
 lib/regex_internal.h | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4535bb5..cd19897 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-06-13  Paul Eggert  <[email-masked]>
+
+	regex: don't be multithreaded if USE_UNLOCKED_IO.
+	Problem reported by Michael Felt in: http://bugs.gnu.org/17773
+	* lib/regex_internal.h: Do not use multithreaded version if
+	USE_UNLOCKED_IO is defined.  This is a hack, but it works
+	around a porting bug with coreutils 8.22 on AIX 7.1.
+
 2014-06-11  Daiki Ueno  <[email-masked]>
 
 	gettext: update macros to version 0.19
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index a0eae33..bfce99f 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -40,7 +40,7 @@
 # define lock_fini(lock) 0
 # define lock_lock(lock) __libc_lock_lock (lock)
 # define lock_unlock(lock) __libc_lock_unlock (lock)
-#elif defined GNULIB_LOCK
+#elif defined GNULIB_LOCK && !defined USE_UNLOCKED_IO
 # include "glthread/lock.h"
   /* Use gl_lock_define if empty macro arguments are known to work.
      Otherwise, fall back on less-portable substitutes.  */
@@ -62,7 +62,7 @@
 # define lock_fini(lock) glthread_lock_destroy (&(lock))
 # define lock_lock(lock) glthread_lock_lock (&(lock))
 # define lock_unlock(lock) glthread_lock_unlock (&(lock))
-#elif defined GNULIB_PTHREAD
+#elif defined GNULIB_PTHREAD && !defined USE_UNLOCKED_IO
 # include <pthread.h>
 # define lock_define(name) pthread_mutex_t name;
 # define lock_init(lock) pthread_mutex_init (&(lock), 0)
-- 
1.9.3