summaryrefslogtreecommitdiff
path: root/src/thread/pthread_once.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread/pthread_once.c')
-rw-r--r--src/thread/pthread_once.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/thread/pthread_once.c b/src/thread/pthread_once.c
index 05ebe69c..b7388b93 100644
--- a/src/thread/pthread_once.c
+++ b/src/thread/pthread_once.c
@@ -10,8 +10,12 @@ int __pthread_once(pthread_once_t *control, void (*init)(void))
{
static int waiters;
- /* Return immediately if init finished before */
- if (*control == 2) return 0;
+ /* Return immediately if init finished before, but ensure that
+ * effects of the init routine are visible to the caller. */
+ if (*control == 2) {
+ a_barrier();
+ return 0;
+ }
/* Try to enter initializing state. Three possibilities:
* 0 - we're the first or the other cancelled; run init