tests/posix: test pthread_key_create in key dtor
@@ -21,7 +21,7 @@ static void dtor2(void *arg) {
dtors_entered++;
}
-static void *worker(void *arg) {
+static void *worker1(void *arg) {
(void)arg;
pthread_key_t key1, key2;
@@ -39,6 +39,32 @@ static void *worker(void *arg) {
return NULL;
}
+static void dtor3(void *arg) {
+ (void)arg;
+
+ // Make sure that we can create and destroy keys inside the dtor.
+ pthread_key_t dtorKey;
+ assert(!pthread_key_create(&dtorKey, NULL));
+
+ assert(!pthread_setspecific(dtorKey, &dtorKey));
+ assert(pthread_getspecific(dtorKey) == &dtorKey);
+
+ assert(!pthread_key_delete(dtorKey));
+}
+
+static void *worker2(void *arg) {
+ (void)arg;
+
+ pthread_key_t key;
+ assert(!pthread_key_create(&key, dtor3));
+
+ assert(!pthread_setspecific(key, &key));
+ assert(pthread_getspecific(key) == &key);
+
+ pthread_exit(0);
+ return NULL;
+}
+
int main() {
// NOTE that the EINVAL return from pthread_setspecific is mlibc-specific,
// POSIX specifies that accessing an invalid key is undefined behavior.
@@ -53,7 +79,7 @@ int main() {
assert(!pthread_key_delete(key));
pthread_t thread;
- assert(!pthread_create(&thread, NULL, &worker, NULL));
+ assert(!pthread_create(&thread, NULL, &worker1, NULL));
assert(!pthread_join(thread, NULL));
assert(pthread_getspecific(key) == NULL);
@@ -62,5 +88,8 @@ int main() {
assert(dtors_entered == 2);
+ assert(!pthread_create(&thread, NULL, &worker2, NULL));
+ assert(!pthread_join(thread, NULL));
+
return 0;
}
