On Tue Jul 4 15:55:21 2023 +0000, Fabian Maurer wrote:
I'd avoid unnecessary local variables and compare
Sure, it was just meant as a quick proof of concept. I pushed a new and more compact version.
You should also probably do:
`if (!(ref = InterlockedOr(&impl->ref_public, 0)))`
Maybe, although I currently don't see how a lack of interlocked would hurt. Would you mind explaining what might go wrong? Maybe because the value could be cached by the compiler or something? I'm not sure.
I think so, as the access is neither volatile nor atomic the compiler has more freedom into its optimisations and may perhaps move the comparison out of the loop (although the atomic operation next to it on the same variable might prevent it).
I usually prefer to avoid non-atomic accesses on variables that are used for synchronization altogether to avoid this kind of potential pitfall.