Skip to content

Commit e4b3df5

Browse files
Christopher Friedtcfriedt
authored andcommitted
tests: posix: pthread: identify thread ids of detached threads
Previously, the number 2 seemed to be somewhat magical. This removes some of the mystery by labeling it. So threads >= DETACH_THR_ID will be detached (we should not attempt to join detached threads). Signed-off-by: Christopher Friedt <[email protected]>
1 parent dbf7003 commit e4b3df5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tests/posix/common/src/pthread.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <zephyr/sys/util.h>
1111
#include <zephyr/ztest.h>
1212

13+
#define DETACH_THR_ID 2
14+
1315
#define N_THR_E 3
1416
#define N_THR_T 4
1517
#define BOUNCES 64
@@ -202,7 +204,7 @@ static void *thread_top_term(void *p1)
202204
zassert_false(ret, "Unable to set cancel state!");
203205
}
204206

205-
if (id >= 2) {
207+
if (id >= DETACH_THR_ID) {
206208
zassert_ok(pthread_detach(self), "failed to set detach state");
207209
zassert_equal(pthread_detach(self), EINVAL, "re-detached thread!");
208210
}
@@ -355,15 +357,17 @@ ZTEST(pthread, test_pthread_termination)
355357
zassert_equal(ret, EINVAL, "invalid cancel state set!");
356358

357359
for (i = 0; i < N_THR_T; i++) {
358-
pthread_join(newthread[i], &retval);
360+
if (i < DETACH_THR_ID) {
361+
zassert_ok(pthread_join(newthread[i], &retval));
362+
}
359363
}
360364

361365
/* TESTPOINT: Test for deadlock */
362366
ret = pthread_join(pthread_self(), &retval);
363367
zassert_equal(ret, EDEADLK, "thread joined with self inexplicably!");
364368

365369
/* TESTPOINT: Try canceling a terminated thread */
366-
ret = pthread_cancel(newthread[N_THR_T/2]);
370+
ret = pthread_cancel(newthread[0]);
367371
zassert_equal(ret, ESRCH, "cancelled a terminated thread!");
368372
}
369373

0 commit comments

Comments
 (0)