Bug#312382: libglib2.0-0: gthread shouldn't abort when stacksize cannot be set

Michael Banck Michael Banck <mbanck@debian.org>, 312382@bugs.debian.org
Tue, 7 Jun 2005 22:04:38 +0200


--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Package: libglib2.0-0
Severity: normal
Tags: patch

Hi,

I filed this upstream as #304790, but it is a major issue, so I
duplicate it here:

Although GNU/Hurd's libpthread includes a pthread_attr_setstacksize()
function, it is mostly a stub and returns EINVAL except if the caller
specifies a stack
size of 2MB.

However, gthread just bails out if pthread_attr_setstacksize() fails,
resulting in e.g. gnome-display-properties and nautilus to abort upon
startup:

GThread-ERROR **: file gthread-posix.c: line 310 (): error 'Invalid
argument' during 'pthread_attr_setstacksize (&attr, stack_size)'
aborting...

Instead, we believe it should not fail if this optional feature cannot
be met and simply continue.

Neal Walfield has written some more on this at
http://lists.debian.org/debian-hurd/2005/05/msg00117.html:

-begin quote--
Our current libpthread doesn't support floating stacks.  To get at the
thread specific data (TSD), we look at the base of the stack.  To find
the base of the stack, we take the current stack point and bitwise and
it with ~(2MB - 1).  This mode of operation makes supporting user
stacks very difficult as we have no mechanism to express these
constraints to the user.

Currently, pthread_attr_setstacksize is essentially a stub (if the
caller specifies 2MB it succeeds all other values return EINVAL).
glib thinks that since it is present (it checks for it using autoconf,
apparently), it must work.  Arguably, we are not not POSIX compliant:

  The pthread_attr_setstacksize() function shall fail if:

  [EINVAL]
      The value of stacksize is less than {PTHREAD_STACK_MIN} or
      exceeds a system-imposed limit.

Thus for our implementation PTHREAD_STACK_MIN would be 2MB and the
system imposed limit would be 2MB. [...]

Since glib just ignores the stack size parameter if
pthread_attr_setstacksize is not found, it should just ignore any
failure.
--end quote--

Patch from the bug attached.


cheers,

Michael

--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pthread_attr_setstacksize_no_abort.patch"

--- glib2.0-2.6.4/gthread/gthread-posix.c.orig	2005-05-19 20:29:47.000000000 +0200
+++ glib2.0-2.6.4/gthread/gthread-posix.c	2005-05-19 20:34:06.376783904 +0200
@@ -307,7 +307,9 @@
   if (stack_size)
     {
       stack_size = MAX (g_thread_min_stack_size, stack_size);
-      posix_check_cmd (pthread_attr_setstacksize (&attr, stack_size));
+      /* No error check here, because some systems can't do it and
+       * we simply don't want threads to fail because of that. */
+      pthread_attr_setstacksize (&attr, stack_size);
     }
 #endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
 

--FCuugMFkClbJLl1L--