|
|
|
|
|
by maxbond
890 days ago
|
|
> The ABA problem is a false-positive execution of a CAS speculation on a shared memory location. In safe Rust, if I have a mutable reference to Foo, and Foo contains a shared reference to Bar, then no other thread has a mutable reference to Foo or Bar. So no other thread will make a CAS on my reference to Bar, or drop Bar and then allocate something at the same memory address, etc. You could have some higher level ABA problem I suppose, where you acquire a lock, read a value, give up the lock, and then make spurious assumptions about what happens while you've let the lock go. But that's obviously not what we're talking about if we're talking about CAS. (ETA: or if these were application level references, eg indices into a list.) If we're going to implement a lockfree data structure, we're going to need unsafe Rust to hand-roll interior mutability. Because we're going to be sharing mutable state. Which isn't allowed in safe Rust. Or am I mistaken? |
|
Substitute the sleep with a combination of doing computation/work and the OS thread scheduler, and you can see how the bug surfaces.