Skip to content

Commit 0a68392

Browse files
committed
tests: posix: pthread: init pthread_attr_t on each iteration
The `test_pthread_descriptor_leak` test was causing a kernel panic on some platforms. Initially, it was not clear why. The usual cases were examined - race conditions, stack sizes, etc. Still no luck. As it turns out, recycling a thread stack (or at least the `pthread_attr_t`) in-place does not work on some platforms, and we need to reinitialize the `pthread_attr_t` and set set the stack property again prior to calling `pthread_create()`. Signed-off-by: Christopher Friedt <[email protected]> (cherry picked from commit 7c17bda)
1 parent 5db2717 commit 0a68392

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tests/posix/common/src/pthread.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,12 @@ void test_pthread_descriptor_leak(void)
567567
pthread_t pthread1;
568568
pthread_attr_t attr;
569569

570-
zassert_ok(pthread_attr_init(&attr), NULL);
571-
zassert_ok(pthread_attr_setstack(&attr, &stack_e[0][0], STACKS), NULL);
572-
573570
/* If we are leaking descriptors, then this loop will never complete */
574571
for (size_t i = 0; i < CONFIG_MAX_PTHREAD_COUNT * 2; ++i) {
575-
zassert_ok(pthread_create(&pthread1, &attr, create_thread1, NULL),
572+
zassert_equal(0, pthread_attr_init(&attr), NULL);
573+
zassert_equal(0, pthread_attr_setstack(&attr, &stack_e[0][0], STACKS), NULL);
574+
zassert_equal(0, pthread_create(&pthread1, &attr, create_thread1, NULL),
576575
"unable to create thread %zu", i);
577-
zassert_ok(pthread_join(pthread1, &unused), "unable to join thread %zu", i);
576+
zassert_equal(0, pthread_join(pthread1, NULL), "unable to join thread %zu", i);
578577
}
579578
}

0 commit comments

Comments
 (0)