From 348cf7fee4023fce9b023145d89429ee8fdde00d Mon Sep 17 00:00:00 2001
From: Robert Morris <rtm@csail.mit.edu>
Date: Wed, 12 Oct 2022 13:07:55 -0400
Subject: [PATCH] forkret first memory model

---
 kernel/proc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/proc.c b/kernel/proc.c
index 959b778..659ca54 100644
--- a/kernel/proc.c
+++ b/kernel/proc.c
@@ -523,8 +523,11 @@ forkret(void)
     // File system initialization must be run in the context of a
     // regular process (e.g., because it calls sleep), and thus cannot
     // be run from main().
-    first = 0;
     fsinit(ROOTDEV);
+
+    first = 0;
+    // ensure other cores see first=0.
+    __sync_synchronize();
   }
 
   usertrapret();