This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix [BZ #110]


Hi!

This patch adjusts tst-stack1, so that it doesn't rely on user defined stack
being reusable/freeable after successful pthread_join and adjusts comment in
tst-stack3.

2004-05-04  Jakub Jelinek  <jakub@redhat.com>

nptl/
	* tst-stack3.c: Note testing functionality beyond POSIX.
linuxthreads/
	* tst-stack1.c: Don't include mcheck.h.
	(do_test): Make sure user defined stacks aren't reused,
	don't free them at the end.  [BZ #110]

--- libc/nptl/tst-stack3.c.jj	2003-12-18 00:51:51.000000000 +0100
+++ libc/nptl/tst-stack3.c	2004-05-04 20:25:20.517536229 +0200
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
 
@@ -18,7 +18,10 @@
    02111-1307 USA.  */
 
 /* Test whether pthread_create/pthread_join with user defined stacks
-   doesn't leak memory.  */
+   doesn't leak memory.
+   NOTE: this tests functionality beyond POSIX.  In POSIX user defined
+   stacks cannot be ever freed once used by pthread_create nor they can
+   be reused for other thread.  */
 
 #include <limits.h>
 #include <mcheck.h>
--- libc/linuxthreads/tst-stack1.c.jj	2003-12-18 00:48:08.000000000 +0100
+++ libc/linuxthreads/tst-stack1.c	2004-05-04 21:07:28.807433761 +0200
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
 
@@ -17,11 +17,9 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
-/* Test whether pthread_create/pthread_join with user defined stacks
-   doesn't leak memory.  */
+/* Test pthread_create/pthread_join with user defined stacks.  */
 
 #include <limits.h>
-#include <mcheck.h>
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -40,10 +38,8 @@ tf (void *p)
 static int
 do_test (void)
 {
-  mtrace ();
-
   void *stack;
-  int res = posix_memalign (&stack, getpagesize (), 4 * PTHREAD_STACK_MIN);
+  int res = posix_memalign (&stack, getpagesize (), 16 * 4 * PTHREAD_STACK_MIN);
   if (res)
     {
       printf ("malloc failed %s\n", strerror (res));
@@ -54,15 +50,17 @@ do_test (void)
   pthread_attr_init (&attr);
 
   int result = 0;
-  res = pthread_attr_setstack (&attr, stack, 4 * PTHREAD_STACK_MIN);
-  if (res)
-    {
-      printf ("pthread_attr_setstack failed %d\n", res);
-      result = 1;
-    }
-
   for (int i = 0; i < 16; ++i)
     {
+      res = pthread_attr_setstack (&attr, stack + 4 * i * PTHREAD_STACK_MIN,
+				   4 * PTHREAD_STACK_MIN);
+      if (res)
+	{
+	  printf ("pthread_attr_setstack failed %d\n", res);
+	  result = 1;
+	  continue;
+	}
+
       /* Create the thread.  */
       pthread_t th;
       res = pthread_create (&th, &attr, tf, NULL);
@@ -90,7 +88,6 @@ do_test (void)
       result = 1;
     }
 
-  free (stack);
   return result;
 }
 

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]