You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I worked with C++ I found that C++ mutex is heavy:
static_assert(sizeof(std::mutex) == 64); // evaluates to be true, which means C++ mutex takes 64 bytes
So I avoided using, for example, this type:
structCounter {
mutable std::mutex m;
int cnt;
voidinc() const {...}
}; // maybe 68 bytes, while basic int type uses only 4 bytes
std::vector<Counter> vec(1000000); // maybe requires 68MB?
But I found that some Rust code uses Vec<Mutex<T>> type. Isn't it heavy? Or is Rust designed to avoid this problem?
The text was updated successfully, but these errors were encountered:
You may also be interested in rust-lang/rust#93740, which has more detail on how Rust moved from pthread to futex based locks for more efficient implementation.
As the issue also states, efficient lock implementation really depends on what the underlying OS provides, so something like mutex's size really can't be fixed.
When I worked with C++ I found that C++ mutex is heavy:
So I avoided using, for example, this type:
But I found that some Rust code uses
Vec<Mutex<T>>
type. Isn't it heavy? Or is Rust designed to avoid this problem?The text was updated successfully, but these errors were encountered: