Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Thread-Safety in Go - An Overlooked Concern (Go...

Preslav Mihaylov
July 01, 2021
77

Thread-Safety in Go - An Overlooked Concern (Go Naviro eMeetup)

A talk on learning the fundamentals of thread-safety in Go as presented at Go Naviro eMeetup (https://www.gonaviro.com/blog/2021/05/thread-safety-in-go-thursday-1st-july)

Materials - http://bit.ly/thread-safety-go

Preslav Mihaylov

July 01, 2021
Tweet

Transcript

  1. 👋 🚗 Software Engineer @ Uber 🎤 Tech. Trainer &

    Speaker ✍ Blogging at pmihaylov.com 󰞵 Open-sourcing at github.com/preslavmihaylov
  2. What’s covered 1. What does “thread-safety” mean? 2. Should you

    care about it at all? 3. Thread-safety problems & solutions a. When is there a potential thread-safety issue? b. Atomic access to shared state c. Delegating thread-safety d. Atomic compound actions e. Visibility & stale data 4. Where to go from here?
  3. “I don’t need thread-safe classes as I’m typically writing web

    apps without spawning any threads…” the average web dev
  4. Non-shared state Stack #1 Thread #1 Non-shared state #1 Non-shared

    state #2 Shared memory aka heap Shared state Non-shared state Stack #2 Thread #2
  5. 1

  6. 2

  7. 3

  8. 4

  9. What’s not covered 1. Initialisation safety & Immutable objects 2.

    Thread-confinement 3. Concurrency tooling - atomic variables/collections, synchronizers 4. Goroutine Management 5. Channels 6. Managing goroutine lifecycle via cancellation/interrupts 7. Dealing with performance/liveness issues (i.e. deadlock, livelock, etc.) 8. The Go Memory Model