Re: [Fwd: Adding GThreadPool API to set per-thread stack size]



On Tue, 2004-07-27 at 08:53, Joe Marcus Clarke wrote:
> On Tue, 2004-07-27 at 03:48, Sebastian Wilhelmi wrote:
> > Hi Joe,
> > 
> > > The latest release of gnome-cups-manager exposed a problem with
> > > GThreadPools on FreeBSD.  Each thread in a thread pool can only have the
> > > default thread stack size.  On FreeBSD, this is 64 KB on most
> > > architectures.  As it turns out, this is not big enough to do CUPS
> > > operations within a thread, and thus gnome-cups-manager crashes with a
> > > stack overflow.
> > 
> > This indeed is unfortunate. On Linux you get some MB (maximum on i386 is
> > 8 MB, can be limited by ulimit -s) virtual memory of stack for every
> > thread. Of course physical memory is only mapped, if it really is used.
> > 
> > The point with thread pools is, that the threads can be reused. That
> > however means that you have to use the standard values for stack size
> > and so on to avoid having to have pools for every parameter combination.
> 
> Then what about adding something like:
> 
> static gulong g_thread_default_stack_size;
> 
> Similar to g_thread_min_stack_size.  This stack size could be a
> reasonable default (e.g. 1 MB).  Programmers could change this still
> using g_thread_create_full() with a different stack_size parameter that
> was > g_thread_min_stack_size.

By the way, the attached patch is what I had in mind of this.  A similar
patch could be applied to gthread-solaris.c.

Joe

-- 
Joe Marcus Clarke
FreeBSD GNOME Team	::	gnome FreeBSD org
FreeNode / #freebsd-gnome
http://www.FreeBSD.org/gnome
--- gthread/gthread-posix.c.orig	Sun Jul 25 02:32:03 2004
+++ gthread/gthread-posix.c	Tue Jul 27 09:26:39 2004
@@ -116,6 +116,7 @@
 #endif /* POSIX_MIN_PRIORITY && POSIX_MAX_PRIORITY */
 
 static gulong g_thread_min_stack_size = 0;
+static gulong g_thread_default_stack_size = 0x100000;
 
 #define G_MUTEX_SIZE (sizeof (pthread_mutex_t))
 
@@ -125,7 +126,8 @@
 g_thread_impl_init()
 {
 #ifdef _SC_THREAD_STACK_MIN
-  g_thread_min_stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN), 0);
+  g_thread_min_stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN),
+    g_thread_min_stack_size);
 #endif /* _SC_THREAD_STACK_MIN */
 #ifdef HAVE_PRIORITIES
 # ifdef G_THREADS_IMPL_POSIX
@@ -306,7 +308,10 @@
 #ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
   if (stack_size)
     {
-      stack_size = MAX (g_thread_min_stack_size, stack_size);
+      if (stack_size > 0)
+        stack_size = MAX (g_thread_min_stack_size, stack_size);
+      else
+	stack_size = MAX (g_thread_default_stack_size, stack_size);
       posix_check_cmd (pthread_attr_setstacksize (&attr, stack_size));
     }
 #endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]