This is an automated email from the ASF dual-hosted git repository.

jiuzhudong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new dd307ab82ce libc/pthread: Avoid compiler optimizations for 
once_control->done
dd307ab82ce is described below

commit dd307ab82cea5ea1893cee46742175726bd7be19
Author: yukangzhi <[email protected]>
AuthorDate: Tue Jan 21 19:14:48 2025 +0800

    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 <[email protected]>
---
 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;
 };
 

Reply via email to