The relatively large size of std::mutex
on different platforms (e.g. 40 or even 80 bytes) is often explained as ensuring the mutexes don't occupy the same cache-lines and so don't incur logically unnecessary fetches and synchronization activity.
However a std::mutex
is commonly embedded in a larger object and its very size is (almost by design) a detriment to true sharing.
What is a good designs for a minimal mutex?
A one-byte spin-lock design is fairly trivial but a 'true' mutex in which threads suspend until notified is more of a challenge. I can't find a portable way for a thread to notify another thread to unsuspend/unsleep without resorting to a mutex.