This is surprising. Why wasn't it working ?
Rémy.
"Is this a recommended pattern for managing shared state with Go?"
From effective Go: http://golang.org/doc/effective_go.html#sharing
Concurrent programming in many environments is made difficult by the subtleties required to implement correct access to shared variables. Go encourages a different approach in which shared values are passed around on channels and, in fact, never actively shared by separate threads of execution. Only one goroutine has access to the value at any given time. Data races cannot occur, by design. To encourage this way of thinking we have reduced it to a slogan:
Do not communicate by sharing memory; instead, share memory by communicating.
I *think* you need to change your thinking on this: forget about blocking function call semantics. What you want (I think) is to protect one or more resources, i.e. give only "atomic" access?
If that's the case then your solution would be:1) a unique goroutine that reads from a channel and then performs logic atomically (update the webcounter)2) concurrent clients that write to the channel (trigger an update)If the clients needs a return value it can pass in a channel in the request which is unique to that particular client. This will have the effect of blocking on the client goroutine as well (when it waits for the results to come back).