I've been reading the documentation on the atomic package and
looking some examples available in the internet and still have some
doubts.
I understand that using atomic.Store() my program can write
a value and suffer no interruption while doing this. What I
still don't know is if I may run many goroutines that may
eventually write on the same address without "messing" it.
By "messing" it I must specify that there is absolutely no
problem for me if more than one goroutine write on the
same place provided that there's no mixture of the context
written. Specifically I have an array of structs with two int64
fields and the goroutines will write to into different places
of this array. It would be very nice if I could allow them to
write there and use no mutexes nor channels to control
the access. Again, there is no problem if one goroutine
writes over a place in the array just to have this place written
by another goroutine the very first moment after. The only
thing that must not happen is data written from one goroutine
in one place being mixed with the data from the other goroutine.
For example:
goroutine 1 writes a[0].Store(mytype{A:3,B:7})
goroutine 2 writes a[0].Store(mytype{A:12,B:1})
It's perfectly ok for me if a[0] ends up with either mytype{A:3,B:7}
or mytype{A:12,B:1}. But trouble comes if a[0] ends up with mytype{A:12,B:7}
or anything like this.
So, using atomic and no mutexes or channel techniques guarantees
data integrity as described above or do I need control the write access
with mutexes / channels?
Thank you in advance
--
Luis Otavio de Colla Furquim
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.