/plushcap/analysis/launchdarkly/golang-pearl-thread-safe-writes-and-double-checked-locking-in-go

Golang pearl: Thread-safe writes and double-checked locking in Go

What's this blog post about?

The text discusses the use of lock-based concurrency in Go programming, specifically for lazy initialization problems where a resource is expensive to construct but read often and written only once. It presents two approaches using read/write locks and sync.atomic package respectively, and finally introduces the sync.Once utility which encapsulates all the locking logic. The author emphasizes that channels should be the first choice for structuring concurrent programs in Go, and these low-level synchronization primitives are last-resort options.

Company
LaunchDarkly

Date published
July 21, 2015

Author(s)
John Kodumal

Word count
562

Hacker News points
None found.

Language
English


By Matt Makai. 2021-2024.