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

On Sunday, February 19, 2017 at 9:32:28 AM UTC+2, Jesse McNelis wrote:
>
> On Sun, Feb 19, 2017 at 3:59 PM, Marwan abdel moneim <mrwn...@gmail.com 
> <javascript:>> 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.

Reply via email to