Golang pearl: Thread-safe writes and double-checked locking in Go
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
Language
English
Hacker News points
None found.