Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardGoGo memory model and happens-beforeSingle-choice MCQ

Two goroutines run with no synchronization. One does `a = 1; b = 2`. The other reads `b` then `a`. The reader sees b==2. What does the 2022-revised Go memory model say about whether the reader must then see a==1, and about 'out-of-thin-air' values?

var a, b int // G1 func g1() { a = 1; b = 2 } // G2 (no synchronization with G1) func g2() { r1 := b r2 := a _ = r1; _ = r2 }