Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCRuntime incompatibility with older version in mutex code #4730

Closed
roozbehid-ic opened this issue Jun 17, 2024 · 2 comments
Closed

VCRuntime incompatibility with older version in mutex code #4730

roozbehid-ic opened this issue Jun 17, 2024 · 2 comments
Labels
invalid This issue is incorrect or by design

Comments

@roozbehid-ic
Copy link

Describe the bug

VS 17.10 C++ runtime broke following code. Code is compiled with VS 17.10 but it doesnt work anymore with previously deployed VC runtime.

Command-line test case

C:\Temp>type ConsoleApplication5.cpp
#include <iostream>
#include <mutex>
std::mutex mtx;

void testmethod() {
        std::scoped_lock lock{ mtx };
        std::cout << "lock worked!\n";
}
int main()
{
    std::cout << "Start!\n";
    testmethod();
    std::cout << "End!\n";
}

Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33811 for x64
  Copyright (C) Microsoft Corporation.  All rights reserved.
  cl /c /Zi /W3 /WX- /diagnostics:column /sdl /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++17 /permissive- /Fo"x64\Release\\" /Fd"x64\Release\vc143.pdb" /external:W3 /Gd /TP /FC /errorReport:prompt ConsoleApplication5.cpp

C:\Temp>.\ConsoleApplication5.exe
Start!

C:\Temp>

Expected behavior

Lock does not crash.
Crashing computer had following version of VCRuntime
msvcp140.dll 14.32.31326.0
vcruntime140.dll 14.32.31326.0

working computer has
msvcp140.dll 14.40.33810.0
vcruntime140.dll 14.40.33810.0

C:\Temp>.\ConsoleApplication5.exe
Start!
lock worked!
End!

C:\Temp>

``
@cpplearner
Copy link
Contributor

This is by design. See https://github.com/microsoft/STL/wiki/Changelog#vs-2022-1710

  • 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.

@roozbehid-ic
Copy link
Author

Thanks for the info. Closing the issue

@StephanTLavavej StephanTLavavej added the invalid This issue is incorrect or by design label Jun 17, 2024
ffiirree added a commit to ffiirree/Capturer that referenced this issue Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This issue is incorrect or by design
Projects
None yet
Development

No branches or pull requests

3 participants