Accessing or modifying a standard Go map simultaneously from multiple goroutines without synchronization.
Go standard `map` types are not thread-safe. If one goroutine writes to a map while another goroutine reads or writes to it concurrently, Go detects data corruption and immediately crashes the entire process.
Spawning multiple goroutines (e.g., via `go func()`) that access a shared global or package-level map without acquiring a mutex lock (`sync.RWMutex`) or using `sync.Map`.
1package main2import "time"3 4func main() {5 m := make(map[string]int)6 go func() {7 for i := 0; i < 1000; i++ {8 m["key"] = i // Write9 }10 }()11 go func() {12 for i := 0; i < 1000; i++ {13 _ = m["key"] // Read14 }15 }()16 time.Sleep(time.Second)17}1package main2import (3 "sync"4 "time"5)6 7type SafeMap struct {8 mu sync.RWMutex9 m map[string]int10}11 12func main() {13 sm := SafeMap{m: make(map[string]int)}14 15 go func() {16 for i := 0; i < 1000; i++ {17 sm.mu.Lock()18 sm.m["key"] = i19 sm.mu.Unlock()20 }21 }()22 23 go func() {24 for i := 0; i < 1000; i++ {25 sm.mu.RLock()26 _ = sm.m["key"]27 sm.mu.RUnlock()28 }29 }()30 time.Sleep(time.Second)31}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
Two goroutines execute concurrently, reading and writing to map `m` at the same time. Go's runtime detects race condition markers and halts execution with a fatal crash.