Patchwork [committed] Fix bug 34544 - pthread_default_stacksize_np failed

login
register
mail settings
Submitter John David Anglin
Date Aug. 8, 2010, 3:33 p.m.
Message ID <20100808153343.86A0D4D2B@hiauly1.hia.nrc.ca>
Download mbox | patch
Permalink /patch/61216/
State New
Headers show

Comments

John David Anglin - Aug. 8, 2010, 3:33 p.m.
This change fixes the failure of the boehm-gc testsuite on hppa*-*-hpux11*.
The boehm garbage collector needs a larger stacksize than the default hpux
pthread stacksize.  It calls pthread_default_stacksize_np to increase
the stacksize, but this fails since pthread_default_stacksize_np must be
called before any threads are created.

We were using pthread_create in gthr-posix.h to determine if pthreads
are active.  However, this breaks pthread_default_stacksize_np.  The only
other pthread call that has a return value of ENOSYS when threads are not
active is pthread_attr_init, but it also breaks pthread_default_stacksize_np.
So, I switched to using pthread_default_stacksize_np in query mode.  It
returns an old size of zero when threads are not active.

Tested with trunk and 4.5 on hppa2.0w-hp-hpux11.11.  Committed to trunk,
4.5 and 4.4.

Dave

Patch

Index: gthr-posix.h
===================================================================
--- gthr-posix.h	(revision 162948)
+++ gthr-posix.h	(working copy)
@@ -273,32 +273,18 @@ 
 
 static volatile int __gthread_active = -1;
 
-static void *
-__gthread_start (void *__arg __attribute__((unused)))
-{
-  return NULL;
-}
-
 static void __gthread_active_init (void) __attribute__((noinline));
 static void
 __gthread_active_init (void)
 {
   static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
-  pthread_t __t;
-  pthread_attr_t __a;
-  int __result;
+  size_t __s;
 
   __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
   if (__gthread_active < 0)
     {
-      __gthrw_(pthread_attr_init) (&__a);
-      __gthrw_(pthread_attr_setdetachstate) (&__a, PTHREAD_CREATE_DETACHED);
-      __result = __gthrw_(pthread_create) (&__t, &__a, __gthread_start, NULL);
-      if (__result != ENOSYS)
-	__gthread_active = 1;
-      else
-	__gthread_active = 0;
-      __gthrw_(pthread_attr_destroy) (&__a);
+      pthread_default_stacksize_np (0, &__s);
+      __gthread_active = __s ? 1 : 0;
     }
   __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
 }
Index: gthr-posix95.h
===================================================================
--- gthr-posix95.h	(revision 162948)
+++ gthr-posix95.h	(working copy)
@@ -197,32 +197,18 @@ 
 
 static volatile int __gthread_active = -1;
 
-static void *
-__gthread_start (void *arg __attribute__((unused)))
-{
-  return NULL;
-}
-
 static void __gthread_active_init (void) __attribute__((noinline));
 static void
 __gthread_active_init (void)
 {
   static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
-  pthread_t t;
-  pthread_attr_t a;
-  int result;
+  size_t __s;
 
   __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
   if (__gthread_active < 0)
     {
-      __gthrw_(pthread_attr_init) (&a);
-      __gthrw_(pthread_attr_setdetachstate) (&a, PTHREAD_CREATE_DETACHED);
-      result = __gthrw_(pthread_create) (&t, &a, __gthread_start, NULL);
-      if (result != ENOSYS)
-	__gthread_active = 1;
-      else
-	__gthread_active = 0;
-      __gthrw_(pthread_attr_destroy) (&a);
+      pthread_default_stacksize_np (0, &__s);
+      __gthread_active = __s ? 1 : 0;
     }
   __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
 }