3 ms·
This demonstrates the ABA problem in safe Rust: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=09c69a493385f4f86687fb1ca12a904c https:/
by infamouscow 3y ago
This demonstrates the ABA problem in safe Rust: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=09c69a493385f4f86687fb1ca12a904c https://play.rust-lang.org/?version=stable&mode=debug&editio...
Substitute the sleep with a combination of doing computation/work and the OS thread scheduler, and you can see how the bug surfaces.
- maxbond 3y agoI guess? I've only ever heard about the ABA problem in reference to pointers, eg in the context of lockfree queues. Maybe that's my ignorance. (Which is why I addressed shared references in my comment.) Yes, if you don't hold a lock on a value, or exert some kind of control at the API level (eg making it monotonic so your CAS will work), you can't make assumptions about it. I think you'll find that Rust developers understand that concept about as well as any other community of concurrent developers. But yes, granted, the semantic information about these integers isn't represented in Rust's type system, and won't be caught by it's static analysis.