mmcgrana/gobyexample — pull request #54 by ryanbrainard (2013-10-20 17:07:27+00:00)
Title: Move `state` variable internal to stateful goroutine.

This is more of a question about Go phrased as a pull request than a request for you to actually change this example. Pull this in if it makes sense, but I'd really just like to know if this is a better or worse way of doing things.

In the `stateful-goroutines` example, the `state` is at the top-level of the `main` function and then a goroutine owns any changes this state via `readOp`s and `writeOp`s. Because the `state` is external to the goroutine, there is nothing stopping others from sidestepping the synchronization and manipulating it on their own. This change moves the `state` internal to the goroutine to control access.

I'm just wondering if this was an oversight in the example or if there is a reason I'm missing to have the state outside the function.