From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v1] pthread_detach/1-2: Fix race condition between thread exit and join
Date: Fri, 8 May 2026 10:00:58 +0000 [thread overview]
Message-ID: <20260508100101.7741-1-wegao@suse.com> (raw)
Latest test in our openqa setup(kernel 7.0.3) show following error:
FAILED: We were able to join a detached thread.
Add a second synchronization semaphore to ensure the child thread remains alive until
the main thread has completed its checks can make test case pass.
Signed-off-by: Wei Gao <wegao@suse.com>
---
.../interfaces/pthread_detach/1-2.c | 25 +++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c
index dc5ed39d3..1a9650f49 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c
@@ -92,6 +92,7 @@
/********************************************************************************************/
static unsigned int sc;
+static sem_t sem_exit;
static void *threaded(void *arg)
{
@@ -113,6 +114,15 @@ static void *threaded(void *arg)
UNRESOLVED(errno, "Failed to post the semaphore");
}
+ /* Wait for the main thread to allow exit */
+ do {
+ ret = sem_wait(&sem_exit);
+ }
+ while ((ret == -1) && (errno == EINTR));
+ if (ret == -1) {
+ UNRESOLVED(errno, "Failed to wait for the exit semaphore");
+ }
+
return arg;
}
@@ -125,6 +135,11 @@ int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
scenar_init();
+ ret = sem_init(&sem_exit, 0, 0);
+ if (ret != 0) {
+ UNRESOLVED(errno, "Failed to init the exit semaphore");
+ }
+
for (sc = 0; sc < NSCENAR; sc++) {
#if VERBOSE > 0
output("-----\n");
@@ -202,11 +217,21 @@ int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
("We were able to join a detached thread.");
}
+ /* Allow the thread to exit */
+ do {
+ ret = sem_post(&sem_exit);
+ }
+ while ((ret == -1) && (errno == EINTR));
+ if (ret == -1) {
+ UNRESOLVED(errno, "Failed to post the exit semaphore");
+ }
+
/* Let the thread an additionnal row to cleanup */
sched_yield();
}
}
+ sem_destroy(&sem_exit);
scenar_fini();
#if VERBOSE > 0
output("-----\n");
--
2.52.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2026-05-08 10:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 10:00 Wei Gao via ltp [this message]
2026-05-08 11:20 ` [LTP] pthread_detach/1-2: Fix race condition between thread exit and join linuxtestproject.agent
2026-05-09 7:39 ` [LTP] [PATCH v2] pthread_detach_1-2: Fix failure on modern glibc Wei Gao via ltp
2026-05-15 9:56 ` [LTP] " linuxtestproject.agent
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260508100101.7741-1-wegao@suse.com \
--to=ltp@lists.linux.it \
--cc=wegao@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox