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
24 lines
362 B
Go
24 lines
362 B
Go
// PREDICT what f() and g() return, and the order of the deferred prints.
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
func f() (x int) {
|
|
defer func() { x++ }()
|
|
return 5
|
|
}
|
|
|
|
func g() int {
|
|
x := 5
|
|
defer func() { x++ }()
|
|
return x
|
|
}
|
|
|
|
func main() {
|
|
fmt.Println(f())
|
|
fmt.Println(g())
|
|
for i := 0; i < 3; i++ {
|
|
defer fmt.Println("deferred:", i) // when and in what order?
|
|
}
|
|
}
|