by sesm · 1y ago · 0 comments
`let lock = Arc::new(Mutex::new(0_u32));`
Doesn't this mean that Mutex introduces one more pointer?
For example, in Java every Object has a built-in mutex, adding some memory overhead in order to remove one extra layer of pointer dereferencing. As far as I understand, Rust introduces an extra layer of pointer indirection with Mutex, which can hurt performance significantly with cache misses.
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.
No. That syntax is roughly equivalent to the following C++:
auto const lock = std::make_shared<std::pair<std::mutex, uint32_t>>(
std::piecewise_construct,
std::make_tuple(),
std::make_tuple(0));