On Sun, Feb 19, 2017 at 3:59 PM, Marwan abdel moneim <mrwnm...@gmail.com> wrote: > i'm reading a book about concurrency, and was doing some baby steps > so i'm trying to manage a variable changes to be locked when a process > starts and freed when it ends > > this is the initial code https://play.golang.org/p/qGraa8yQEc > and this is my solution https://play.golang.org/p/wC9tcbpVjf > > my question is, when i run the last code through the race detector i get > this > > while it actually works as it should be ( the first invoked goruotines lock > the variable and even if it takes time, the other goroutines can't access > the variable) > > so is there any problem here? >
The problem is that assignment to a bool doesn't trigger synchronisation between processors. Each processor will continue to only see their own version of the value of the variable 'locked', until such time as synchronisation occurs. A sync.Mutex will trigger synchronisation when locked and unlocked. -- 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.