--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The fields being sorted by do indeed have a data race, however the size of the slice is constant (there's an mtx protecting modification of the slice) so given sort knows the length, it shouldn't try to access beyond it surely?
I'm guessing the new sort changes aren't safe if the Less is indeterministic even though the max length is know?
On Wed, Feb 17, 2016 at 8:12 PM, Steven Hartland <steven....@multiplay.co.uk> wrote:
The fields being sorted by do indeed have a data race, however the size of the slice is constant (there's an mtx protecting modification of the slice) so given sort knows the length, it shouldn't try to access beyond it surely?
I'm guessing the new sort changes aren't safe if the Less is indeterministic even though the max length is know?
I believe Sort has always relied on the fact that the ordering of values doesn't change mid-sort. It was never safe, now it just happens to go wrong loudly instead of quietly :).
I'm actually ok with slight inaccurate results if the data changes, but as it knows the array bounds it should never try to access beyond them.
Ignoring the race for a minute is seems likely we could see the same issue with non-strict ordered data too, which would be quite a change in spec would it not?
Changing equality check to comparison (as in old version) will fix an "issue", but i don't think it is issue: you shall not sort mutating data.
Precisely. Less cannot be random! Any callback-sort from the original C-library qsort to now expects that compare(a,b) is a proper function for fixed a and b. If you violate that on purpose, or by race condition accident, you are not honoring the contract that makes the whole notion work.
But if you makes personal project, then it is "quick and dirty" way to "sort by priority and get some random elements from min/max/mean priority".
Is Go only for good teams, or for "teenagers" also?
Isn't definition of Less() quite unambiguous? where is the room in the spec to return random or inconsistent answer. the way I read it, Less has to be consistent as well as transitive as well.
type Interface interface { // Len is the number of elements in the collection. Len() int // Less reports whether the element with // index i should sort before the element with index j. Less(i, j int) bool // Swap swaps the elements with indexes i and j. Swap(i, j int) }
type Interface interface { // Len is the number of elements in the collection. Len() int // Less reports whether the element with // index i should sort before the element with index j. Less(i, j int) bool // Swap swaps the elements with indexes i and j. Swap(i, j int) }
> If there are data races, you don't have any correctness guarantees.
This is not a true statement.
It is also not true that for any given
protocol, a lack of data races implies correct behavior.
2016-02-22 18:38 GMT-08:00 Caleb Spare <ces...@gmail.com>:
>> > If there are data races, you don't have any correctness guarantees.
>>
>> This is not a true statement.
>
> I'm talking about Go, as specified today. If you still disagree, please
> explain.
Perhaps you were stating this as applied to usage of Sort, but it is
stated absolutely. It is not absolutely true, so I wanted to clarify
that point, regardless of what is possible with Go today.
That said, I do still disagree: one can implement lock-free data
structures on top of sync.atomic such that data races are present, but
such that operations linearize. Linearization provides a correctness
guarantee, and some (but by far not all) of these structures can be
implemented in Go, as specified today.
An atomic pointer load, followed by non-atomic reads of that memory
into local state, followed by a CAS of the original pointer are likely
to trip the race detector, and still seem to qualify as a "data race"
given your definition. (And the race detector will -- or at least used
to; I haven't tried recently -- flag the non-atomic reads. I'd be
surprised if it didn't anymore, because then it could prove
linearization, which seems out of its capability.)
This is how many
non-blocking data structures work.
I do agree that it is uncommon, so this is probably a silly argument.
But data races do not automatically imply lack of correctness in Go or
in any other language that provides RMW primitives like CAS. And
that's my point: the existence or lack of a data race by itself says
nothing about the correctness of a program, and therefore labeling
something as a data race is almost entirely useless for formal
discussions of correctness.