The Collator type in golang.org/x/text/collate stores two iterator
slots as struct fields (_iter [2]iter). Both Compare and CompareString
write into these shared fields during comparison, making concurrent
calls on the same Collator instance unsafe.
A data race occurs when a single Collator is used as a comparison
closure across multiple goroutines, for example as a Less() function
passed to parallel sort workers in a database engine.
The race can be detected with go test -race on any program that
calls CompareString or Compare from two goroutines sharing one
Collator.
A fix is proposed in golang/text#60 which
removes the shared iterator state and declares iter variables as
goroutine-local stack allocations in Compare and CompareString.
The Collator type in golang.org/x/text/collate stores two iterator
slots as struct fields (_iter [2]iter). Both Compare and CompareString
write into these shared fields during comparison, making concurrent
calls on the same Collator instance unsafe.
A data race occurs when a single Collator is used as a comparison
closure across multiple goroutines, for example as a Less() function
passed to parallel sort workers in a database engine.
The race can be detected with go test -race on any program that
calls CompareString or Compare from two goroutines sharing one
Collator.
A fix is proposed in golang/text#60 which
removes the shared iterator state and declares iter variables as
goroutine-local stack allocations in Compare and CompareString.