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

Two goroutines run; the main goroutine reads x after receiving from ch. Under the Go memory model, what is guaranteed about the value printed?

package main import "fmt" var x int var ch = make(chan struct{}) func main() { go func() { x = 42 ch <- struct{}{} }() <-ch fmt.Println(x) }