olahol / melody

:notes: Minimalist websocket framework for Go
BSD 2-Clause "Simplified" License
3.75k stars 366 forks source link

No need Mutex if you use Channel. Am I right? #20

Closed ianberdin closed 7 years ago

ianberdin commented 7 years ago

I'm talk about https://github.com/olahol/melody/blob/master/hub.go#L34-L36 and code below

ianberdin commented 7 years ago

Access tot hub.session already synchronous, because channels not buffered.

https://blog.golang.org/share-memory-by-communicating

ianberdin commented 7 years ago

It's code totally synchronous... https://github.com/olahol/melody/blob/master/examples/gophers/main.go

olahol commented 7 years ago

It's locked because hub.sessions can be accessed asynchronously by hub.len().

https://github.com/olahol/melody/blob/master/hub.go#L71-L76

What's the problem with https://github.com/olahol/melody/blob/master/examples/gophers/main.go ?

ianberdin commented 7 years ago

Understand, thank you