pthread_key_delete
Andreas Schwab
schwab@suse.de
Thu Dec 13 01:30:00 GMT 2001
pthread_key_delete should not try to contact the thread manager if that
does not exist yet. Otherwise this program hangs:
#include <pthread.h>
#include <stdio.h>
int
main ()
{
pthread_key_t k;
pthread_key_create (&k, NULL);
pthread_key_delete (k);
return 0;
}
Andreas.
2001-12-13 Andreas Schwab <schwab@suse.de>
* specific.c (pthread_key_delete): Don't contact the thread
manager if no threads have been created yet.
--- specific.c.~1.13.~ Thu Nov 29 10:40:10 2001
+++ specific.c Thu Dec 13 10:26:16 2001
@@ -102,25 +102,28 @@
/* Set the value of the key to NULL in all running threads, so
that if the key is reallocated later by pthread_key_create, its
- associated values will be NULL in all threads. */
+ associated values will be NULL in all threads.
- {
- struct pthread_key_delete_helper_args args;
- struct pthread_request request;
-
- args.idx1st = key / PTHREAD_KEY_2NDLEVEL_SIZE;
- args.idx2nd = key % PTHREAD_KEY_2NDLEVEL_SIZE;
- args.self = 0;
-
- request.req_thread = self;
- request.req_kind = REQ_FOR_EACH_THREAD;
- request.req_args.for_each.arg = &args;
- request.req_args.for_each.fn = pthread_key_delete_helper;
-
- TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request,
- (char *) &request, sizeof(request)));
- suspend(self);
- }
+ Do nothing if no threads have been created yet. */
+
+ if (__pthread_manager_request != -1)
+ {
+ struct pthread_key_delete_helper_args args;
+ struct pthread_request request;
+
+ args.idx1st = key / PTHREAD_KEY_2NDLEVEL_SIZE;
+ args.idx2nd = key % PTHREAD_KEY_2NDLEVEL_SIZE;
+ args.self = 0;
+
+ request.req_thread = self;
+ request.req_kind = REQ_FOR_EACH_THREAD;
+ request.req_args.for_each.arg = &args;
+ request.req_args.for_each.fn = pthread_key_delete_helper;
+
+ TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request,
+ (char *) &request, sizeof(request)));
+ suspend(self);
+ }
pthread_mutex_unlock(&pthread_keys_mutex);
return 0;
--
Andreas Schwab "And now for something
Andreas.Schwab@suse.de completely different."
SuSE Labs, SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
More information about the Libc-hacker
mailing list