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 are the possible outputs? What's the race here even if it
|
||||
// "usually works"? Run with -race a few times.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var wg sync.WaitGroup
|
||||
count := 0
|
||||
for i := 0; i < 3; i++ {
|
||||
go func() {
|
||||
wg.Add(1) // <-- what's wrong with Add here?
|
||||
defer wg.Done()
|
||||
count++
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
fmt.Println("count:", count)
|
||||
}
|
||||
Reference in New Issue
Block a user