microsoft / STL

MSVC's implementation of the C++ Standard Library.
Other
10.15k stars 1.5k forks source link

<mutex>: change mutex to be an SRWLOCK #946

Open Amaroker opened 4 years ago

Amaroker commented 4 years ago

Description std::mutex is currently powered by ConcRT to support Windows XP. As a result the size of mutex is too big to fit in a cache line.

When XP support can be dropped, the size can be reduced to sizeof(void*) by changing mutex to be an SRWLOCK, which is the highest performance lock provided by Windows.

Semi-duplicate description

Additional context See also: Developer Community DevCom-334696 and Microsoft-internal VSO-685103 / AB#685103.

vNext note: Resolving this issue will require breaking binary compatibility. We won't be able to accept pull requests for this issue until the vNext branch is available. See #169 for more information.

AlexGuteniev commented 4 years ago

I'm not sure if it should be precisely SRWLOCK.

WaitOnAddress is also optimal, it can inline fast path, have 1 byte size, and allows implementing timed mutex without adding CONDITION_VARIABLE to the picture.

Still there are drawbacks of WaitOnAddress too, specifically having a fallback on Windows 7, and lack of debugging facilities (such as Application Verifier hooks).


But I'm sure we deserve something better than we have right now :-)

StephanTLavavej commented 4 years ago

Thanks, I've linked the Microsoft-internal bug to this issue! (And @BillyONeal implemented it in our long-lost vNext branch in 2018, but we'll have to retrieve that work from cryo-storage.)

Chronial commented 4 years ago

Duplicate to #654?

StephanTLavavej commented 4 years ago

Thanks @Chronial - they do look like near-duplicates, although that issue also talks about recursive_mutex. @AlexGuteniev, would you like me to fuse these issues together?

AlexGuteniev commented 4 years ago

Yes, sure

StephanTLavavej commented 1 year ago

Well, it's always an SRWLOCK now, it's just unnecessarily big until vNext, so I suppose we should keep that label.