Should sync/atomic support bitwise operations?
Closed this issue · 2 comments
I've got this data structure that has a flags field that is a bitfield of flags. Since the field is read often but modified seldom, it is accessed using atomic operations rather than being protected by a lock or by doing a message exchange with the relevant goroutine. No problem when reading the field, but since sync/atomic doesn't support bitwise and and or, modifying the field requires a CAS loop.
Should bitwise and and or be added to the set of atomic operations in sync/atomic? I'm a little ambivalent on the issue — on the one hand, they would be a natural addition, on the other hand, the issue is easily worked around using a CAS loop.
Should sync/atomic support bitwise operations?
IMO not.
We generally err on the side of not adding API when it's possible to avoid, so I'm going to close this until there's a strong need and/or major performance win for enough callers.