Explainers · Short

Your Go counter is lying to you

Published
Duration
Language
English

Watch on YouTube ↗

Transcript

Text of the video's narration.

A thousand gophers add one to a counter. They came back with six hundred seventy-five. Two of them read the same number at once, and one update vanished. With the race flag, Go blows the whistle on the count plus plus line. Fix one: a sync.Mutex.

One gopher through the door at a time. A thousand. Fix two: one boss gopher owns the counter and the rest pass it notes on a channel. Also a thousand. Which wins? The Go wiki says whichever is simplest, and for a counter that's the padlock.

Credits and notes

  • The Go gopher was designed by Renée French. Licensed under CC BY 4.0. go.dev/blog/gopher
  • Changes: poses (rotation, mirroring, squash), props and effects added; no recolour. Source file: gophercolor.png from the official Go website repo (github.com/golang/website, _content/doc/gopher).
  • Music: original lofi bed generated in code (royalty-free, see LICENSE-music.md).
  • Narrated with Phonon; motion in Remotion.

More in this series · Explainers