tokio-rs / loom

Concurrency permutation testing tool for Rust.
MIT License
2.14k stars 111 forks source link

No get_mut method on AtomicPtr #154

Open jrmuizel opened 4 years ago

jrmuizel commented 4 years ago

The AtomicPtr implementation seems to be missing an implementation of get_mut

Restioson commented 4 years ago

Would a PR to implement this be accepted?

hawkw commented 4 years ago

@Restioson

Would a PR to implement this be accepted?

Yes, that would be great! It should probably be simulated using Atomic::unsync_load: https://github.com/tokio-rs/loom/blob/73e6c14da41978e7a20e1993c2554a16a3dcb597/src/rt/atomic.rs#L200-L216

We might want to add get_mut methods to the other loom atomic types, like AtomicUsize, since they also have get_mut methods.

carllerche commented 4 years ago

If we do get_mut() it needs to return a guard type and not the ptr itself. loom needs to know when the ptr is no longer accessible in order to ensure correctness. This is why other types have with_mut but that can be changed to a guard type return as well instead of a closure.

Restioson commented 4 years ago

Would the logic be essentially the same as with_mut otherwise? The cleanup moved to the drop impl and the setup to the get_mut function?