Doing it in C would also require a mutex or other synchronization primitive.
On Sun, Feb 19, 2017 at 7:11 AM Marwan abdel moneim <mrwnm...@gmail.com> wrote: > i didn't want to use Mutex because i wanted to learn the topic from the > beginning, and see how it could be done without channels or Mutex > > like how you could do it in C for example > > > On Sunday, February 19, 2017 at 3:32:52 PM UTC+2, jmont...@dyn.com wrote: > > > On Sunday, February 19, 2017 at 3:41:13 AM UTC-5, Marwan abdel moneim > wrote: > > i wanted to do it without a Mutex > but there still something not clear to me, but i don't know what it is > and i don't understand what "trigger" synchronization means > > i will keep reading, and go back to it later and see it i get it > > thanks for your help > > > To correctly do any sort of write access to the same location from > multiple goroutines *will *require synchronization. Without it, your code > will never be correct. It may work some of the time, or even all of the > time on some platform with some version of the compiler. But it will never > be guaranteed to always work, unless you use synchronization. If you really > don't want to use a sync.Mutex <https://golang.org/pkg/sync/#Mutex>, then > you should look at sync/atomic <https://golang.org/pkg/sync/atomic>. But > be forewarned, doing anything but the most trivial synchronization with > atomics is hard o get right. > > On a more general note, I think there is sometimes an over eagerness to > attempt "lock free". If you are trying to solve a real problem, I suggest > thinking about channel based solutions. If they are not appropriate, just > use sync.Mutex, or one of the other synchronization types. Only try to > optimize to "lock free" (atomics) if you find there is an actual problem > with lock contention under real conditions. > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.