Skip to content

Conversation

@cpplearner
Copy link
Contributor

@cpplearner cpplearner commented Jun 23, 2023

Fixes #2285.

Because this might cause problem in complicated (and formally forbidden) scenarios (see discussion in #3770), I chose to make this opt-in via the _USE_CONSTEXPR_MUTEX_CONSTRUCTOR macro. If _USE_CONSTEXPR_MUTEX_CONSTRUCTOR is not defined, mutex will call _Mtx_init_in_situ as before.

For the same reason, I changed stl_critical_section_win7 and stl_condition_variable_win7 back to polymorphic classes, even though their vptrs are no longer accessed. (If _USE_CONSTEXPR_MUTEX_CONSTRUCTOR is defined, no stl_critical_section_win7 object will be created.)

@cpplearner cpplearner requested a review from a team as a code owner June 23, 2023 10:00
@cpplearner cpplearner marked this pull request as draft June 23, 2023 10:27
@cpplearner cpplearner marked this pull request as ready for review June 23, 2023 11:01
@StephanTLavavej

This comment was marked as resolved.

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Jun 23, 2023
@StephanTLavavej StephanTLavavej self-assigned this Jun 23, 2023
@StephanTLavavej
Copy link
Member

Thanks, this looks great! I pushed extremely minor changes.

Having thought about this extensively during the previous PR, I think that this change is correct and safe, and it's a good simplification too.

@StephanTLavavej StephanTLavavej self-assigned this Jul 13, 2023
@StephanTLavavej

This comment was marked as outdated.

@StephanTLavavej StephanTLavavej removed their assignment Jul 13, 2023
@StephanTLavavej
Copy link
Member

Unfortunately, I need to pull this from the merge batch. It's causing the internal build to consistently fail with:

D:\msvc\src\vctools\asan\mt\llvm-symbolizer.nativeproj(79,5): error MSB3073:
The command ""D:\msvc\src\ExternalAPIs\cmake\bin\ninja.exe" "bin/llvm-symbolizer.exe"   " exited with code 1.

I don't know what's causing this yet.

@StephanTLavavej
Copy link
Member

We're very close to understanding the root cause - the MSVC-internal build is using fresh STL headers, but a previously installed copy of msvcp140.dll on the system. The fix will also be MSVC-internal; it appears that this PR is working by design (we knew that it would require an updated DLL).

@CaseyCarter
Copy link
Contributor

We're very close to understanding the root cause - the MSVC-internal build is using fresh STL headers, but a previously installed copy of msvcp140.dll on the system. The fix will also be MSVC-internal; it appears that this PR is working by design (we knew that it would require an updated DLL).

In other words: Thanks for finding a bug in our internal build!

@StephanTLavavej
Copy link
Member

We'll need to ensure that the VCRedist is unlocked for this.

@StephanTLavavej StephanTLavavej added the affects redist Results in changes to separately compiled bits label Jul 14, 2023
@StephanTLavavej
Copy link
Member

⚠️ Note to self: This requires MSVC-internal changes...

... found by @zacklj89 (:heart_eyes_cat:); I will investigate adding a complete set of DLLs to that list.

@MahmoudGSaleh will notify the appropriate people that 17.8 Preview 2 needs to have an unlocked VCRedist.

@StephanTLavavej StephanTLavavej self-assigned this Jul 20, 2023
strega-nil added a commit to strega-nil/llvm-project that referenced this pull request Aug 18, 2023
It turns out that the STL requires you to place the DLLs into the
directory of the executable; else, msvcp140.dll will be taken from
C:\Windows\System32 (which is unsupported).

This was discovered because of the recent constexpr mutex change;
see [microsoft/STL#3824][]. Especially the fuzzer unit tests fail
completely with the mutex changes.

[microsoft/STL#3824]: microsoft/STL#3824

Differential Revision: https://reviews.llvm.org/D158221
CaseyCarter added a commit to CaseyCarter/STL that referenced this pull request Aug 30, 2023
This reverts commit 8d18fec.

Conflicts:
* stl/inc/xthreads.h
* stl/src/cond.cpp
* stl/src/mutex.cpp
* stl/src/primitives.hpp
tianleiwu pushed a commit to microsoft/onnxruntime that referenced this pull request Jun 12, 2024
microsoft/STL#3824 introduces constexpr mutex.
An older version of msvcp140.dll will lead to ```A dynamic link library
(DLL) initialization routine failed```.

This error can be encountered if using conda Python since conda packages
msvc dlls and these are older right now.

This PR disables the constexpr mutex so that ort package can work with
older msvc dlls.

Thanks @snnn for the discovery.
baijumeswani added a commit to microsoft/onnxruntime that referenced this pull request Jun 20, 2024
microsoft/STL#3824 introduces constexpr mutex.
An older version of msvcp140.dll will lead to ```A dynamic link library
(DLL) initialization routine failed```.

This error can be encountered if using conda Python since conda packages
msvc dlls and these are older right now.

This PR disables the constexpr mutex so that ort package can work with
older msvc dlls.

Thanks @snnn for the discovery.
yf711 pushed a commit to microsoft/onnxruntime that referenced this pull request Jun 21, 2024
microsoft/STL#3824 introduces constexpr mutex.
An older version of msvcp140.dll will lead to ```A dynamic link library
(DLL) initialization routine failed```.

This error can be encountered if using conda Python since conda packages
msvc dlls and these are older right now.

This PR disables the constexpr mutex so that ort package can work with
older msvc dlls.

Thanks @snnn for the discovery.
narknon added a commit to UE4SS-RE/RE-UE4SS that referenced this pull request Jun 22, 2024
microsoft/STL#3824
microsoft/STL#4000
microsoft/STL#4339

Add escape hatch due to STL change resulting in issues with binary compatibility.

https://github.com/microsoft/STL/wiki/Changelog
"Fixed bugs:

    Fixed mutex's constructor to be constexpr. #3824 #4000 #4339
        Note: Programs that aren't following the documented restrictions on binary compatibility may encounter null dereferences in mutex machinery. You must follow this rule:

            When you mix binaries built by different supported versions of the toolset, the Redistributable version must be at least as new as the latest toolset used by any app component.

        You can define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR as an escape hatch."
narknon added a commit to UE4SS-RE/RE-UE4SS that referenced this pull request Jun 27, 2024
STL updates Mutex Fix

microsoft/STL#3824
microsoft/STL#4000
microsoft/STL#4339

Add escape hatch due to STL change resulting in issues with binary compatibility.

https://github.com/microsoft/STL/wiki/Changelog
"Fixed bugs:

    Fixed mutex's constructor to be constexpr. #3824 #4000 #4339
        Note: Programs that aren't following the documented restrictions on binary compatibility may encounter null dereferences in mutex machinery. You must follow this rule:

            When you mix binaries built by different supported versions of the toolset, the Redistributable version must be at least as new as the latest toolset used by any app component.

        You can define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR as an escape hatch."**Description**
barcharcraz pushed a commit to barcharcraz/llvm-project that referenced this pull request Nov 1, 2024
See [MSVC-PR-490940][] and [LLVM-D158221][].

It turns out that the STL requires you to place the DLLs into the
directory of the executable; else, `msvcp140.dll` will be taken from
`C:\Windows\System32` (which is unsupported).

This was discovered because of the recent constexpr mutex change;
see [microsoft/STL#3824][]. Especially the fuzzer unit tests fail
completely with the mutex changes.

[MSVC-PR-490940]: https://dev.azure.com/devdiv/DevDiv/_git/msvc/pullrequest/490940
[LLVM-D158221]: https://reviews.llvm.org/D158221
[microsoft/STL#3824]: microsoft/STL#3824
kirides added a commit to kirides/GD3D11 that referenced this pull request May 8, 2025
Merge SaiyansKing readme changes and workaround for old "critical section" usage, update readme

- Add Linux Wine Example
- Update readme
- @SaiyansKing fixed possible crash with mutex usage on newer c++:
  > VS 2022 17.10:
  > 
  > - Fixed bugs:
  >   - Fixed mutex's constructor to be constexpr. [#3824](microsoft/STL#3824) [#4000](microsoft/STL#4000) [#4339](microsoft/STL#4339)
Note: Programs that aren't following the documented [restrictions on binary compatibility](https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017?view=msvc-170) may encounter null dereferences in mutex machinery. You must follow this rule:
When you mix binaries built by different supported versions of the toolset, the Redistributable version must be at least as new as the latest toolset used by any app component.
  > 
  > - You can define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR as an escape hatch.
rohan11235813 pushed a commit to quadric-io/onnxruntime that referenced this pull request Aug 19, 2025
microsoft/STL#3824 introduces constexpr mutex.
An older version of msvcp140.dll will lead to ```A dynamic link library
(DLL) initialization routine failed```.

This error can be encountered if using conda Python since conda packages
msvc dlls and these are older right now.

This PR disables the constexpr mutex so that ort package can work with
older msvc dlls.

Thanks @snnn for the discovery.
rohan11235813 pushed a commit to quadric-io/onnxruntime that referenced this pull request Sep 15, 2025
microsoft/STL#3824 introduces constexpr mutex.
An older version of msvcp140.dll will lead to ```A dynamic link library
(DLL) initialization routine failed```.

This error can be encountered if using conda Python since conda packages
msvc dlls and these are older right now.

This PR disables the constexpr mutex so that ort package can work with
older msvc dlls.

Thanks @snnn for the discovery.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects redist Results in changes to separately compiled bits bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<mutex> : std::mutex::mutex is not constexpr

5 participants