Coroutines for Go
This post is about why we need a coroutine package for Go, and what it would look like. But first, what are coroutines?
Visit research.swtch.com → RSS feedOn Hacker News Feb 2010 – Jan 2026
Software Engineering 32Open Source 11Programming Languages 9Tools & Productivity 8Systems & Performance 8Security & Privacy 7
This post is about why we need a coroutine package for Go, and what it would look like. But first, what are coroutines?
The current Go language memory model was written in 2009, with minor updates since. It is clear that there are at least a few details that we should add to the current memory model, among them an explicit endorsement of race detectors and a clear statement of how the APIs in sync/atomic synchronize programs.
Programming language memory models answer the question of what behaviors parallel programs can rely on to share memory between their threads. For example, consider this program in a C-like language, where both x and done start out zeroed.
Last week, I gave a talk about Go at the Boston Google Developers Group meeting. There were some problems with the recording, so I have rerecorded the talk as a screencast and posted it on YouTube.
When explaining Go to new programmers, I've found that it often helps to explain what Go values look like in memory, to build the right intuition about which operations are expensive and which are not. This post is about basic types, structs, arrays, and slices.
Go's interfaces—static, checked at compile time, dynamic when asked for—are, for me, the most exciting part of Go from a language design point of view. If I could export one feature of Go into other languages, it would be interfaces.
Go is defined to be a safe language. Indices into array or string references must be in bounds; there is no way to reinterpret the bits of one type as another, no way to conjure a pointer out of thin air; and there is no way to release memory, so no chance of “ dangling pointer ” errors and the associated memory…
Generic data structures (vectors, queues, maps, trees, and so on) seem to be the hot topic if you are evaluating a new language. One of the most frequent questions we've had about Go is where the generics are. It seems like there are three basic approaches to generics:
The official Go proposal is at https://golang.org/issue/24301 , filed on March 20, 2018 and accepted on May 21, 2018.