This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: Re-use of user-defined stacks for threads
- To: drepper at cygnus dot com
- Subject: Re: Re-use of user-defined stacks for threads
- From: Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>
- Date: 3 Dec 2000 12:28:33 -0000
- CC: libc-alpha at sources dot redhat dot com
- References: <20001125113341.29693.qmail@md.dent.med.uni-muenchen.de> <m3n1ejst6b.fsf@otr.mynet.cygnus.com>
Hello,
> Probably the joining thread should deallocate the stack somehow.
> Don't know yet what the solution should be.
OK, how about the appended patch instead? I've only verified
it passes make check so far, but will investigate further.
Regards,
Wolfram.
2000-12-02 Wolfram Gloger <wg@malloc.de>
* manager.c (__pthread_handle_free): New function.
* internals.h: Declare __pthread_handle_free.
* join.c (pthread_join): Reclaim thread resources immediately in
the context of the joining thread rather than via the manager.
--- internals.h 2000/12/03 10:42:39 1.1
+++ internals.h 2000/12/03 11:36:27
@@ -468,6 +468,9 @@
void __pthread_wait_for_restart_signal(pthread_descr self);
+/* Assumes handle->h_lock is already locked. */
+void __pthread_handle_free(pthread_handle handle);
+
int __pthread_yield (void);
/* Global pointers to old or new suspend functions */
--- join.c 2000/12/03 10:37:10 1.1
+++ join.c 2000/12/03 11:52:02
@@ -106,7 +106,6 @@
int pthread_join(pthread_t thread_id, void ** thread_return)
{
volatile pthread_descr self = thread_self();
- struct pthread_request request;
pthread_handle handle = thread_handle(thread_id);
pthread_descr th;
pthread_extricate_if extr;
@@ -161,15 +160,9 @@
}
/* Get return value */
if (thread_return != NULL) *thread_return = th->p_retval;
- __pthread_unlock(&handle->h_lock);
- /* Send notification to thread manager */
- if (__pthread_manager_request >= 0) {
- request.req_thread = self;
- request.req_kind = REQ_FREE;
- request.req_args.free.thread_id = thread_id;
- __libc_write(__pthread_manager_request,
- (char *) &request, sizeof(request));
- }
+ /* Reclaim resources immediately; if the user supplied a stack, it
+ must be reusable as soon as pthread_join() returns. */
+ __pthread_handle_free(handle);
return 0;
}
--- manager.c 2000/12/03 10:36:33 1.1
+++ manager.c 2000/12/03 11:56:47
@@ -791,7 +791,6 @@
static void pthread_handle_free(pthread_t th_id)
{
pthread_handle handle = thread_handle(th_id);
- pthread_descr th;
__pthread_lock(&handle->h_lock, NULL);
if (nonexisting_handle(handle, th_id)) {
@@ -800,7 +799,15 @@
__pthread_unlock(&handle->h_lock);
return;
}
- th = handle->h_descr;
+ __pthread_handle_free(handle);
+}
+
+/* Assumes handle->h_lock is already locked. */
+
+void __pthread_handle_free(pthread_handle handle)
+{
+ pthread_descr th = handle->h_descr;
+
if (th->p_exited) {
__pthread_unlock(&handle->h_lock);
pthread_free(th);