Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Go's race detector has a mutex blind spot. Parent comment
Specifically for Go, I'd try to address the problem in CSP style, so as to avoid explicit locks unless absolutely necessary.
Now for the case you mention, one can actually achieve the same in Go, it just takes a bit of prior work to set up the infra.
type Foo struct {sync.Mutex; s string} func doLocked[T sync.Locker](data T, fn func(data T)) { data.Lock(); defer data.Unlock(); fn(data) } func main() { foo := &Foo{s: "Hello"} doLocked(foo, func(foo *Foo) { /* ... */ }) /* do the slow stuff */ }
There are no comments on this comment yet.
Specifically for Go, I'd try to address the problem in CSP style, so as to avoid explicit locks unless absolutely necessary.
Now for the case you mention, one can actually achieve the same in Go, it just takes a bit of prior work to set up the infra.