Re: [go-nuts] no.something seem like impossible,but it happens!!!!【 string 】causes the crash !!!!!!!!!!!!!!
On Wed, Jul 26, 2017 at 02:46:08AM -0700, 370265...@qq.com wrote: > > I think I can see at least one data race in your code. Try to run it using > > the race detector to verify. > thanks.yes,i thought this before too,but string is basic type of golang,to > read and write the same variable of string should not case panic i think. Implementing this would mean each access to each string variable would need to use some sort of locking. This is not tolerable as 99.9% of code accessing variables of any type, including string, is not subject for concurrency matters as such variables are confined to particular goroutines. Using automatic locking in such cases would cause tremendous slowdowns for no reason. That is, when you need concurrency, plan for concurrency and implement it one way or another -- either through using channels or explicit locking. -- 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.
Re: [go-nuts] no.something seem like impossible,but it happens!!!!【 string 】causes the crash !!!!!!!!!!!!!!
thanks.yes,i thought this before too,but string is basic type of golang,to read and write the same variable of string should not case panic i think. 在 2017年7月26日星期三 UTC+8下午5:35:24,Jan Mercl写道: > > On Wed, Jul 26, 2017 at 11:28 AM <3702...@qq.com > wrote: > > I think I can see at least one data race in your code. Try to run it using > the race detector to verify. > > -- > > -j > -- 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.
Re: [go-nuts] no.something seem like impossible,but it happens!!!!【 string 】causes the crash !!!!!!!!!!!!!!
On Wed, Jul 26, 2017 at 11:28 AM <370265...@qq.com> wrote: I think I can see at least one data race in your code. Try to run it using the race detector to verify. -- -j -- 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.
[go-nuts] no.something seem like impossible,but it happens!!!!【 string 】causes the crash !!!!!!!!!!!!!!
the code is like this(i make it simple,but the logic is not change) const ( Ignore = "-" End= "\r\n" ) type AccessLog struct { Hash string LowerIP string FlowType int8 SendTime int64 Host string AppName string StreamName string Protocol string StatusCode string Url string HttpAgentstring Referstring VideoFrameRate int32 . . . omit some variable . . . } func appendValue(rsp string, value string) string { if value == End { // End rsp += value } else { rsp += (value + "|") } return rsp } func (a *AccessLog) SetStatusCode(statusCode string) { if a.StatusCode == "" { a.StatusCode = statusCode } } func (a *AccessLog) MakeString() string { var rsp string rsp = appendValue(rsp, Stop) rsp = appendValue(rsp, a.Hash) rsp = appendValue(rsp, a.LowerIP) rsp = appendValue(rsp, fmt.Sprint(a.FlowType)) rsp = appendValue(rsp, fmt.Sprint(tt)) rsp = appendValue(rsp, a.Host) rsp = appendValue(rsp, a.AppName) rsp = appendValue(rsp, a.StreamName) rsp = appendValue(rsp, a.Protocol) rsp = appendValue(rsp, a.StatusCode) *//every time crash in this line,and panic: **runtime error: invalid memory address or nil pointer dereference* rsp = appendValue(rsp, a.Url) rsp = appendValue(rsp, Ignore) rsp = appendValue(rsp, Ignore) . . . } *2 goroutinue will access the same variable which is type of *AccessLog ,like this* func changeAccessLog(a *AccessLog){ . . . a.SetStatusCode(code) . . . } func makeStringAccessLog(a *AccessLog) { . . . rsp := a.MakeString() . . . } *//this is the caller function* func callFunc(){ . . . a := new(AccessLog) go changeAccessLog(a) go makeStringAccessLog(a) . . . } so, i don't understand why operate string variable will case crash. of course,the code in my program is more complex,function SetStatusCode and MakeString will be called in the same time. do somebody meet this before??? -- 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.