[PATCH] Minimal stack sizes for threads




On some systems there is a minimal stack size for threads. This size
can be obtained with the sysconf function. The following patch changes
gthread-posix.c and ghtread-solaris.c to use this.

Index: gthread/gthread-posix.c
===================================================================
RCS file: /cvs/gnome/glib/gthread/gthread-posix.c,v
retrieving revision 1.13
diff -u -r1.13 gthread-posix.c
--- gthread/gthread-posix.c	1999/11/16 10:29:27	1.13
+++ gthread/gthread-posix.c	2000/02/20 19:40:59
@@ -37,6 +37,9 @@
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 
 #define posix_print_error( name, num )                          \
   g_error( "file %s: line %d (%s): error %s during %s",         \
@@ -221,6 +224,11 @@
 			    gpointer thread)
 {
   pthread_attr_t attr;
+#ifdef _SC_THREAD_STACK_MIN
+  gulong min_stack_size = sysconf (_SC_THREAD_STACK_MIN);
+#else
+  gulong min_stack_size = 0;
+#endif
 
   g_return_if_fail (thread_func);
 
@@ -228,7 +236,10 @@
   
 #ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
   if (stack_size)
+    {
+      stack_size = MAX (min_stack_size, stack_size);
       posix_check_for_error (pthread_attr_setstacksize (&attr, stack_size));
+    }
 #endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
 
 #ifdef PTHREAD_SCOPE_SYSTEM
Index: gthread/gthread-solaris.c
===================================================================
RCS file: /cvs/gnome/glib/gthread/gthread-solaris.c,v
retrieving revision 1.6
diff -u -r1.6 gthread-solaris.c
--- gthread/gthread-solaris.c	1999/11/16 10:29:27	1.6
+++ gthread/gthread-solaris.c	2000/02/20 19:40:59
@@ -35,6 +35,9 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 
 #define solaris_print_error( name, num )                        \
   g_error( "file %s: line %d (%s): error %s during %s",         \
@@ -190,9 +193,15 @@
 			      gpointer thread)
 {     
   long flags = (bound ? THR_BOUND : 0) | (joinable ? 0: THR_DETACHED);
-  
+#ifdef _SC_THREAD_STACK_MIN
+  gulong min_stack_size = sysconf (_SC_THREAD_STACK_MIN);
+#else
+  gulong min_stack_size = 0;
+#endif
+
   g_return_if_fail (thread_func);
   
+  stack_size = MAX (min_stack_size, stack_size);
   solaris_check_for_error (thr_create (NULL, stack_size,  
 				       (void* (*)(void*))thread_func,
 				       arg, flags, thread));



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