Slice
- ? Will multiple goroutine change the same slice cause data problem? Like 1000 append times just add 999 values actually.
- ? A goroutine use len(slice) to get length and another goroutine append some data which trigge the underlying array changed, will the len(slice) get the old length OR new length OR just crash because the old array does not exist?
Slice
- ? Will multiple goroutine change the same slice cause data problem? Like 1000 append times just add 999 values actually.
reading and writing values in parallel (without append, reslice) is OK.
Urgh, to the list this time.
I don't believe so, not unless the address of a was passed to another goroutine.
--
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.
It is safe,
go printlength(a)
a = append(a, v)
There is no race here, a is an immutable value
It's definitely a race.a is immutable in the same way that an int is immutable; you can still assign on top of it, which is what's happening here, and doing it concurrently with reading is unsafe.On Thu, Apr 2, 2015 at 2:55 PM, Dave Cheney <da...@cheney.net> wrote:It is safe,
go printlength(a)
a = append(a, v)There is no race here, a is an immutable value
a = append(a, v) in concurrent with len(a) is a problem