Skip to content

Commit 7c17bda

Browse files
cfriedtjgl-meta
authored andcommitted
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]>
1 parent 27c25e9 commit 7c17bda

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

tests/posix/common/src/pthread.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,10 @@ ZTEST(posix_apis, test_pthread_descriptor_leak)
588588
pthread_t pthread1;
589589
pthread_attr_t attr;
590590

591-
zassert_ok(pthread_attr_init(&attr));
592-
zassert_ok(pthread_attr_setstack(&attr, &stack_e[0][0], STACKS));
593-
594591
/* If we are leaking descriptors, then this loop will never complete */
595592
for (size_t i = 0; i < CONFIG_MAX_PTHREAD_COUNT * 2; ++i) {
593+
zassert_ok(pthread_attr_init(&attr));
594+
zassert_ok(pthread_attr_setstack(&attr, &stack_e[0][0], STACKS));
596595
zassert_ok(pthread_create(&pthread1, &attr, create_thread1, NULL),
597596
"unable to create thread %zu", i);
598597
zassert_ok(pthread_join(pthread1, &unused), "unable to join thread %zu", i);

0 commit comments

Comments
 (0)