elast0ny / shared_memory

A Rust wrapper around native shared memory for Linux and Windows
382 stars 51 forks source link

Is the implementation of `Deref` and `DerefMut` for locks safe? #34

Closed asajeffrey closed 5 years ago

asajeffrey commented 5 years ago

The ReadLockGuard and WriteLockGuard types implement Deref and DerefMut respectively, but it is not obvious this is safe. For example, by locking the same area of memory at different types, I can get a &usize and an &AtomicUsize which alias, then storing into the &AtomicUsize causes the &usize to become UB.

asajeffrey commented 5 years ago

This is from https://github.com/elast0ny/shared_memory-rs/issues/33#issuecomment-537482273 but is separate enough that I thought it was worth opening.

elast0ny commented 5 years ago

Follow up on : https://github.com/elast0ny/shared_memory-rs/issues/33#issuecomment-537513888