Re: [go-nuts] Does the code have any concurrent problem?

2019-07-05 Thread White Pure
Thanks for your reply. I've tried before and it reported race. But I don't understand why this code has race, and what's the possible bug? Here's the output: $ go run -race main.go == WARNING: DATA RACE Write at 0x00c96000 by goroutine 7: main.main.func3() /Users/purewh

[go-nuts] Re: Does the code have any concurrent problem?

2019-07-05 Thread White Pure
unc() { for { m.Lock() n = 0 m.Unlock() } }() go func() { for { m.Lock() n -= 1 m.Unlock() } }() } Playground link: https://play.golang.org/p/Mrdetw46mXR 在 2019年7月5日星期五 UTC+8下午6:40:32,White Pure写道: > > Hi, > I wrote some code like below these days, and my colleagues and me are >

[go-nuts] Does the code have any concurrent problem?

2019-07-05 Thread White Pure
Hi, I wrote some code like below these days, and my colleagues and me are not sure if the code has any concurrent problem. Can someone help to figure out if the code has any race problem? Thanks very much! Code: > package main > import ( "sync" "sync/atomic" ) > func main

Re: [go-nuts] Re: A question about A sync.Once implementation.

2019-05-08 Thread White Pure
plete example: https://play.golang.org/p/vWVXzRBPMNe > The question is: according to the Go memory model, what's the set of > possible things that that program can print? > > I think it could print "unexpected value 0" but not "unexpected value 2". > > &g

[go-nuts] Re: A question about A sync.Once implementation.

2019-05-07 Thread White Pure
Hi, Thanks for your reply. The second bug is a known issue, so let’s ignore that. In that case, I think function f still can only be executed once. But why does the load and store of o.done need to be done using atomic operations? I suppose there’s mutex assuring the happens-before.