Patrick Kelly
1 min readAug 8, 2018

--

You should change the title to “Go’s append is not thread safe”. It’s never thread safe. :)

I find slices and append to be maybe the 2nd most confusing thing about go, after make vs new. And slices, IMHO, are very much a compromise. They try to offer a lot of functionality and flexibility, but maintain performance. From that we have the weird behavior that sometimes slices move (requiring the re-assignment), and sometimes they grow in place.

But the real problem here is violating “Do not communicate by sharing memory; instead, share memory by communicating.” (https://blog.golang.org/share-memory-by-communicating)

My understanding is that if it’s not explicitly declared as thread-safe, you’d better assume it’s not. That probably even applies to something as basic as i++.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Patrick Kelly
Patrick Kelly

Written by Patrick Kelly

Web/database engineer/gopher. Cycling, photos, yada, yada.

No responses yet

Write a response