From dd307ab82cea5ea1893cee46742175726bd7be19 Mon Sep 17 00:00:00 2001 From: yukangzhi Date: Tue, 21 Jan 2025 19:14:48 +0800 Subject: [PATCH] libc/pthread: Avoid compiler optimizations for once_control->done Prevent compiler reordering that may read stale value of once_control->done. Use volatile to ensure visibility across threads and prevent incorrect once initialization. Signed-off-by: yukangzhi --- include/pthread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pthread.h b/include/pthread.h index 50ea4fbb80a..561b6070b96 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -402,7 +402,7 @@ typedef struct pthread_barrier_s pthread_barrier_t; struct pthread_once_s { - bool done; + volatile bool done; pthread_mutex_t mutex; };