The Little Book of Semaphores, by professor Allen Downey, is a textbook that introduces the principles of synchronization for concurrent programming. It’s available under the GNU Free Documentation License. The book uses Python to illustrate the concepts, but I think Go is a much better fit for that purpose.

Semaphores are rarely seen in Go as such. The sync package provides synchronization primitives, for example, mutual exclusion locks and condition variables, but notably it doesn’t provide a semaphore. It has the following description:

Package sync provides basic synchronization primitives such as mutual exclusion locks. Other than the Once and WaitGroup types, most are intended for use by low-level library routines. Higher-level synchronization is better done via channels and communication.

This higher-level concept is introduced in Effective Go and expanded in a post by Andrew Gerrand on the Go blog: share memory by communicating. Rob Pike presented Go concurrency patterns at Google I/O 2012 and Sameer Ajmani presented Advanced Go concurrency patterns in 2013.

With such a wealth of resouces, people still look for introductory material. I think the introductory material is well covered, but we’re still missing a bit on the transitory front, along the lines of Andrew’s post.

What I would like to do here is provide that. The Little Book of Semaphores presents a great deal of concurrency problems. I hope to be able to provide equivalent (idiomatic) Go solutions. As usual, feedback and corrections are welcomed!