History & origins of the Go memory model

265 views
Skip to first unread message

Daniel Fava

unread,
Nov 27, 2020, 3:57:17 PM11/27/20
to golang-nuts
Hi,

Does anyone know how the Go memory model came to be?  I don't have technical questions about it.  I just would like to know the historical context.

The model is specified in terms of happens-before, due to Lamport.  But the following rule, which allows channels to be used as locks, was not part of Lamport's original formulation:

"A receive from an unbuffered channel happens before the send on that channel completes. "

I'm curious who (if anyone) was involved in including this rule.  How did it come to be?

I also find it fascinating how the word "completes" seems to make a world of difference.  As I read it, removing the word "completes" from the rule above (and from the rule connecting a sender and its corresponding receiver receiver) would lead to a quite different memory model.  I'm curious how intentional the "completes" is.

Thanks a lot!
Daniel

Ian Lance Taylor

unread,
Nov 27, 2020, 5:47:46 PM11/27/20
to Daniel Fava, golang-nuts
As I recall, Tom Szymanski asked for the rules about when one
goroutine would see changes made by another goroutine, and how that
related to channel operations. Russ Cox described what he thought
should happen, Tom encouraged him to write that down, and Russ did,
winding up with
https://go.googlesource.com/go/+/82c38cf8dd628e6c90b6f1160be2a8d5088b77c9/doc/mem.html
(when reading that doc, remember that it was written in February,
2009, and that the syntax has changed since then).

The "completes" is intentional. A send/receive on an unbuffered
channel was always intended to serve as a synchronization point
between the goroutines. Otherwise it would be hard for different
goroutines to synchronize on anything.

Ian

Daniel Fava

unread,
Dec 2, 2020, 4:01:30 AM12/2/20
to golan...@googlegroups.com
Thanks for this bit of history, Ian!  I’ve been studying the memory model in grad school for a few years now and I think it’s well written.  I was curious about how it came to be.

I think the “completes” also mater for buffered channels, for example:

Daniel
Reply all
Reply to author
Forward
0 new messages