3 ms·
I would suggest you read the source code of Mutex <https://doc.rust-lang.org/src/std/sync/mutex.rs.html#178-182 https://doc.rust-lang.org/src/std/sync/mutex.rs.
by dannymi 2y ago
I would suggest you read the source code of Mutex <https://doc.rust-lang.org/src/std/sync/mutex.rs.html#178-182 https://doc.rust-lang.org/src/std/sync/mutex.rs.html#178-182> and then of UnsafeCell <https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html>.
So, the layout of Mutex<T> is the same as T and then some lock (well, obviously).
>Rust introduces an extra layer of pointer indirection with Mutex, which can hurt performance significantly with cache misses.
Why would there be an extra pointer dereference? There isn't.
- sesm 2y agoThanks for the explanation!