|
|
|
|
|
by optymizer1
4580 days ago
|
|
Interesting. Now, what does SetUser(r, "dave") do? Since you're passing in 'r', it must keep a map of all requests and their data, i.e. map[*http.Request]string ("dave" being the string in this case). This map should be protected by a mutex because it could be written from multiple go-routines. Is this the case? If so, how do we avoid contention on this mutex? |
|
If you had actual shared state that needed to be mutated by concurrent handlers, the idiomatic solution would be to park it behind a channel on its own goroutine; that's why goroutines are so cheap, is so you can allocate them to problems like this. If you want your solution to be general and unfussy, you'd have the channel be of closures; you'd just pass whatever mutating code you want to run to the goroutine.