[go-nuts] confusing a lock demo about https://golang.org/ref/mem#tmp_8

2018-03-13 Thread
var l sync.Mutex var a string func f() { a = "hello, world" l.Unlock() } func main() { l.Lock() go f() l.Lock() print(a) } I'm a new gopher, reading a blog about lock and having a problem, in general , we use sync.Mutex in pairs, in the above code why could it call lock two times in main. Any

[go-nuts] Re: confusing a lock demo about https://golang.org/ref/mem#tmp_8

2018-03-13 Thread
gt; to be an example of good style. As a "new gopher" I would avoid this idiom. > If you did use this, some significant commenting would be needed. > > Also, what blog post are you referring to? > > - Jake > > On Tuesday, March 13, 2018 at 9:27:08 AM UTC-4, 郎凯 wrote: >&g

Re: [go-nuts] confusing a lock demo about https://golang.org/ref/mem#tmp_8

2018-03-13 Thread
Thanks a lot, I also want to know what the first lock meaning is? 在 2018年3月13日星期二 UTC+8下午9:32:35,Burak Serdar写道: > > The second lock waits until f() runs and unlocks the mutex. > > On Tue, Mar 13, 2018 at 3:37 AM, 郎凯 > > wrote: > > var l sync.Mutex > > var a stri

[go-nuts] Re: confusing a lock demo about https://golang.org/ref/mem#tmp_8

2018-03-15 Thread
after function f() is executed. > > regards > Subbu > On Tuesday, March 13, 2018 at 6:27:08 AM UTC-7, 郎凯 wrote: >> >> var l sync.Mutex >> var a string >> >> func f() { >> a = "hello, world" >> l.Unlock() >> } >> >>