From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix [BZ #110]
Date: Tue, 04 May 2004 19:11:00 -0000 [thread overview]
Message-ID: <20040504165932.GN5191@sunsite.ms.mff.cuni.cz> (raw)
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
next reply other threads:[~2004-05-04 19:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-04 19:11 Jakub Jelinek [this message]
2004-05-04 19:25 ` Ulrich Drepper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040504165932.GN5191@sunsite.ms.mff.cuni.cz \
--to=jakub@redhat.com \
--cc=drepper@redhat.com \
--cc=libc-hacker@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).