Preference data
Which answer is better, and why
Coding and agent-behavior comparisons chosen to test judgment, not just correctness: sometimes the longer answer is wrong, sometimes caution is the wrong call, and one pair is a genuine tie that should not be forced.
- 12 pairs
- 10 clear, 2 slight or tie
- Agent safety and honesty cases
- Raw and DPO formats
A counter shared by goroutines
pref-06
Prompt
Is this Go code safe?
var count int
for i := 0; i < 100; i++ {
go func() { count++ }()
}
fmt.Println(count)Response A
No, two problems:
1. count++ from many goroutines is a data race (go run -race reports it); increments can be lost.
2. main prints before the goroutines finish.
var count int64
var wg sync.WaitGroup
for i := 0; i < 100; i++ {
wg.Add(1)
go func() { defer wg.Done(); atomic.AddInt64(&count, 1) }()
}
wg.Wait()
fmt.Println(count) // 100Response B
Yes. The Go scheduler runs goroutines one at a time on a single thread, so count++ is effectively atomic and you will get 100.
Expert judgment
Prefers response AClear preference
B is wrong on both counts: Go runs goroutines in parallel across threads, and the program may print before they finish. A finds both bugs and fixes them with atomic and WaitGroup.