-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync/atomic: atomic.Value doesn't support CompareAndSwap #11260
Comments
/cc @dvyukov |
What if you store uncomparable types in a |
Mutex usually works well for protecting write side of Value. |
@OneOfOne If the only argument is that other languages have it, then I propose to not implement it. |
@dvyukov not at all, I was just giving an example. A good usage case for it is a (doubly) linked list, and avoiding mutexes all together. |
Lock-free doubly-linked lists are insanely difficult to implement and are very slow because (1) link-based data structures are slow due to indirection and (2) shared data structures with high mutation rate are slow due to cache contention. And they can be implemented with atomic.CompareAndSwapPointer. |
I understand that, but atomic.Value is there and it exists, it has Load/Store like the other types in the atomic package, it's missing a function. It's not an addition of a new API, it's adding a missing functionality. |
I think Dmitry is referring to the addition of this new function as "the new API". I don't see how the new API would work with non-comparable values. It seems to invite misuse. To risk repetition, if your use case is pointers then you should use |
Value.Load/Store are different from CompareAndSwap/Add/Exchange:
|
No thanks, per conversation above. |
atomic.Value
should have CompareAndSwap support.If there's interest, I'll clean up my patch and put it up for review.
The text was updated successfully, but these errors were encountered: