[LTP] pthread_detach/1-2: Fix race condition between thread exit and join
linuxtestproject.agent@gmail.com
linuxtestproject.agent@gmail.com
Fri May 8 13:20:13 CEST 2026
Hi Wei,
On Fri, 8 May 2026 10:00:58 +0000, Wei Gao wrote:
> pthread_detach/1-2: Fix race condition between thread exit and join
> + /* Wait for the main thread to allow exit */
> + do {
> + ret = sem_wait(&sem_exit);
> + }
> + while ((ret == -1) && (errno == EINTR));
> + /* Allow the thread to exit */
> + do {
> + ret = sem_post(&sem_exit);
> + }
> + while ((ret == -1) && (errno == EINTR));
> + sem_destroy(&sem_exit);
Correct fix. The second semaphore ensures the child is still alive when
pthread_join() is called, eliminating the race.
Reviewed-by: LTP AI Reviewer <ltp-ai@noreply.github.com>
Pre-existing issues noticed in the surrounding code (not introduced
by this patch):
- 1-2.c: uses testfrmw.h harness with test_main() instead of posixtest.h
and main() — not introduced by this patch.
---
Note:
Our agent completed the review of the patch.
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
More information about the ltp
mailing list