Initial commit: Go SRE interview exercises
Includes solved 02-worker-pool and 09-safe-counter (mutex, atomic, sharded). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GbnJj9ZqEx9nUvzkjdwfMq
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// PREDICT: what happens? Can recover() save you? Run it a few times.
|
||||
// Then run with: go run -race .
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Println("recovered:", r) // will this ever print?
|
||||
}
|
||||
}()
|
||||
m := make(map[int]int)
|
||||
for i := 0; i < 100; i++ {
|
||||
go func(i int) { m[i] = i }(i)
|
||||
}
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
fmt.Println(len(m))
|
||||
}
|
||||
Reference in New Issue
Block a user