What are the concurrency guarantees of goroutines? ;)
> var buttons = []string{"red", "blue", "green", "yellow", "purple"}
The obvious way to solve it in order to get the answer shown in the source code is
if x == 0 {
*sequence = []Button{{"red"}, {"blue"}, {"green"}, {"yellow"}, {"purple"}}
}
return
This way there is nothing concurrently touching sequence, nor is there anything concurrent touching rand, nor is anything relying on goroutine starting order, nor are there other race conditions. But yet the site says this is wrong.How do we know how the puzzle is executed?
And if you're saying some guarantee exists that the last executes first, then the rest execute in order, that's empirically false:
https://play.golang.org/p/3gV0TYG4GQW
1000
773
774
775
776
...