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

Thread-Safety in Go - An Overlooked Concern (Uber Meetups, Sofia)

Thread-Safety in Go - An Overlooked Concern (Uber Meetups, Sofia)

A talk on learning the fundamentals of thread-safety in Go as presented at Uber Meetups, Sofia (https://www.meetup.com/Uber-Engineering-Events-Sofia/)

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

Preslav Mihaylov

May 13, 2021
Tweet

More Decks by Preslav Mihaylov

Other Decks in Programming

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