Should sync.Locker for sync.Once

60 views
Skip to first unread message

aind...@gmail.com

unread,
Apr 9, 2021, 2:07:00 PM4/9/21
to golang-nuts
I've often been in situations where I've wanted to store and error or some other signal once, but wanted reads to the stored value to be synchronized. I've often ended up introducing a secondary mutex, or reimplementing the slow path of sync.Once. This is a common pattern I see across many Go codebases, including the standard library for example: https://golang.org/src/io/pipe.go.

Given this, would it be beneficial for sync.Once to implement Locker? This would allow the mutex to be reused to synchronize access to the value being stored.

aind...@gmail.com

unread,
Apr 9, 2021, 2:07:58 PM4/9/21
to golang-nuts
Argh I messed up the title. It should be "Should sync.Once implement sync.Locker?" Oh well...
Reply all
Reply to author
Forward
0 new messages