Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sharing v isn't the problem. The problem occurs when v is evaluated.

The parent's post has no race condition, as v is evaluated before the goroutine starts.

The top example of my post has a race condition because there is no guarantee when v will be evaluated wrt to the loop.

The bottom example has no race condition because v is evaluated on every iteration and assigned to s, which is used by the goroutine at some point afterwards.



My point still stands: to fix this, you have to realize that (a) v could be shared here and (b) that sharing could be a problem. I suspect the first time most newbies get hit with a race condition here they're going to be beyond baffled.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: