talk-yapc-asia-2015 icon indicating copy to clipboard operation
talk-yapc-asia-2015 copied to clipboard

Data race not fixed using atomic in the talk example

Open Vykstorm opened this issue 2 years ago • 0 comments

In the code example provided in talk.md, the data race condition is not fixed by changing visitors++ statement with atomic.AddInt64(&visitors, 1).

Also,

        w.Write([]byte("<h1 style='color: " + r.FormValue("color") +
             "'>Welcome!</h1>You are visitor number " + fmt.Sprint(visitors) + "!"))

must be changed with

        w.Write([]byte("<h1 style='color: " + r.FormValue("color") +
             "'>Welcome!</h1>You are visitor number " + fmt.Sprint(atomic.LoadInt64(&visitors)) + "!"))

Vykstorm avatar May 25 '22 08:05 Vykstorm