This is the mail archive of the
glibc-bugs@sources.redhat.com
mailing list for the glibc project.
[Bug nptl/454] New: pthread_key_create does not reset key's value to NULL
- From: "gmorin1 at bloomberg dot net" <sourceware-bugzilla at sources dot redhat dot com>
- To: glibc-bugs at sources dot redhat dot com
- Date: 16 Oct 2004 16:37:41 -0000
- Subject: [Bug nptl/454] New: pthread_key_create does not reset key's value to NULL
- Reply-to: sourceware-bugzilla at sources dot redhat dot com
Hi,
In some cases, linuxthreads/nptl do not reset the key value to NULL. If you create a key, set a value
delete it, then create a new one, the value of the newly created key will be the one you set for the
former one. This behavior violates POSIX : "Upon key creation, the value NULL is associated with the
new key in all active threads. Upon thread creation, the value NULL is associated with all defined keys
in the new thread."
Here is a simple program to reproduce the problem:
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
int main(void) {
pthread_key_t k1,k2;
int ret;
ret = pthread_key_create(&k1, NULL);
if (ret) {
printf("pthread_key_create: %s\n", strerror(ret));
return -1;
}
assert(NULL == pthread_getspecific(k1));
ret = pthread_setspecific(k1, (void *) 0xdeafbeefUL);
if (ret) {
printf("pthread_setspecific: %s\n", strerror(ret));
return -2;
}
assert((void *) 0xdeafbeefUL == pthread_getspecific(k1));
ret = pthread_key_delete(k1);
if (ret) {
printf("pthread_key_delete: %s\n", strerror(ret));
return -4;
}
ret = pthread_key_create(&k2, NULL);
if (ret) {
printf("pthread_key_create: %s\n", strerror(ret));
return -5;
}
assert(NULL == pthread_getspecific(k2));
return 0;
}
The last assert fails. I reproduced the problems on different glibc 2.3.{2,3} installations on SuSE and
Debian. Older versions also have the bug. I can reproduce it on a venerable Debian stable.
Guillaume.
--
Summary: pthread_key_create does not reset key's value to NULL
Product: glibc
Version: 2.3.2
Status: NEW
Severity: normal
Priority: P2
Component: nptl
AssignedTo: drepper at redhat dot com
ReportedBy: gmorin1 at bloomberg dot net
CC: glibc-bugs at sources dot redhat dot com
http://sources.redhat.com/bugzilla/show_bug.cgi?id=454
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.