We need to tie the fast-path read with the store, to make sure that when
fast-reading 1, we see all the effects performed by the init routine.

(and we don't need a full barrier, only an acquire/release pair is
needed)

Reported-by: Brent Baccala <[email protected]> 's Claude assistant
---
 sysdeps/htl/pt-once.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/sysdeps/htl/pt-once.c b/sysdeps/htl/pt-once.c
index 5737033bf7..965ab8894c 100644
--- a/sysdeps/htl/pt-once.c
+++ b/sysdeps/htl/pt-once.c
@@ -34,8 +34,7 @@ __pthread_once (pthread_once_t *once_control, void 
(*init_routine) (void))
 {
   ASSERT_TYPE_SIZE (pthread_once_t, __SIZEOF_PTHREAD_ONCE_T);
 
-  atomic_full_barrier ();
-  if (once_control->__run == 0)
+  if (atomic_load_acquire (&once_control->__run) == 0)
     {
       __pthread_spin_wait (&once_control->__lock);
 
@@ -45,8 +44,7 @@ __pthread_once (pthread_once_t *once_control, void 
(*init_routine) (void))
          init_routine ();
          pthread_cleanup_pop (0);
 
-         atomic_full_barrier ();
-         once_control->__run = 1;
+         atomic_store_release (&once_control->__run, 1);
        }
 
       __pthread_spin_unlock (&once_control->__lock);
-- 
2.51.0


Reply via email to