-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Disable constexpr std::mutex on Windows #17991
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It appeared that wget is not present by default on Windows runners, will add explicit install now. |
staticlibs
added a commit
to staticlibs/duckdb-odbc
that referenced
this pull request
Jun 20, 2025
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
On Windows the `constexpr` constructor of `std::mutex`, that was supposed to be there since C++11, was not implemented until VS2022. Its implementation has required to use Slim Reader/Writer (SRW) Locks ([ref](https://learn.microsoft.com/en-us/windows/win32/sync/slim-reader-writer--srw--locks)) that are only supported since Window 7, but VS2019 was still supporting Windows Vista as a target ([more details from SO](https://stackoverflow.com/a/74255773)). The implementation of `constexpr std::mutex` in MSVC has required the ABI breakage in C++ STL that was eventually added in VS2022 17.10 ([commit](microsoft/STL@4aad4b8)). This commit has introduced the macro `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` that can be defined to stay ABI compatible with older versions of C++ stdlib. Thus the binaries built with VS2022 17.10 or later and without this macro cannot be run with older versions of C++ stdlib `msvcp140.dll` even if they do not use `constexpr std::mutex` - any mutex usage will crash with something like this ([more examples and comments from MSFT](https://web.archive.org/web/20250618223106/https://developercommunity.visualstudio.com/t/Access-violation-in-_Thrd_yield-after-up/10664660)): ``` Faulting application name: duckdb.exe, version: 1.3.1.0, time stamp: 0x684fdb82 Faulting module name: MSVCP140.dll, version: 14.36.32532.0, time stamp: 0x04a30cf0 Exception code: 0xc0000005 ``` This PR adds the `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` macro definition to Windows builds assuming that we are not going to use `constexpr` constructor of `std::mutex` and we want to be able to run with `msvcp140.dll` while being compiled with newer toolchains. Note, that running binaries, that were built against `msvcp140.dll` version `14.40+`, in environment with earlier versions `msvcp140.dll` is not officially supported by MSFT ([ref](https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017?view=msvc-170)). But we don't really have a choice here (unless we want to keep DuckDB itself on VS2019). Extensions (which build should include the engine CMake file being update by this PR) are going to be loaded though JDBC into JVM processes. As of mid 2025, OpenJDK builds from some of major vendors (e.g. Amazon Corretto), including the latest stable JDK 24 (released in March 2025) are still using VS2019 (likely the topic of this issue is one of the reasons for that). And all these JDKs include a vendored copy of `msvcp140.dll` version `14.29`. Due to the way, how Windows shared lib loader works, this vendored C++ stdlib will be loaded by the JVM instead of any system one. And then later when the JVM will load DuckDB extensions shared libs through JDBC - these extensions will also use this pre-loaded version of C++ stdlib, as we do not do static linking for it. In general, LTS JDK versions have 10+ years of production support (for example, JDK 6 released in late 2006 is still supported by some vendors). And even if later updates of LTS JDKs (11, 17, 21, 24 etc) will move to a newer version of MSVC toolchain - the old JDK binaries are going to be still in use for a long time. Thus this change is proposed as a permanent change - not a temporary workaround. Testing: additional test run of `unittest.exe` is added that uses `msvcp140.dll` from VS2019 instead of the system-provided one. Fixes: duckdb#17971
716df50
to
a92491b
Compare
staticlibs
added a commit
to staticlibs/duckdb-odbc
that referenced
this pull request
Jun 20, 2025
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
staticlibs
added a commit
to staticlibs/duckdb-odbc
that referenced
this pull request
Jun 20, 2025
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
Windows CI run has passed
I've filed #17993 as an attempt to fix the |
staticlibs
added a commit
to staticlibs/duckdb-odbc
that referenced
this pull request
Jun 20, 2025
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
staticlibs
added a commit
to staticlibs/duckdb-odbc
that referenced
this pull request
Jun 20, 2025
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
staticlibs
added a commit
to staticlibs/duckdb-odbc
that referenced
this pull request
Jun 20, 2025
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
staticlibs
added a commit
to staticlibs/duckdb-odbc
that referenced
this pull request
Jun 20, 2025
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
staticlibs
added a commit
to staticlibs/duckdb-odbc
that referenced
this pull request
Jun 21, 2025
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
Thanks! |
github-actions bot
pushed a commit
to duckdb/duckdb-r
that referenced
this pull request
Jun 27, 2025
Use correct expression function after filter pushdown (duckdb/duckdb#17860) Disable constexpr std::mutex on Windows (duckdb/duckdb#17991)
github-actions bot
added a commit
to duckdb/duckdb-r
that referenced
this pull request
Jun 27, 2025
Use correct expression function after filter pushdown (duckdb/duckdb#17860) Disable constexpr std::mutex on Windows (duckdb/duckdb#17991) Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
staticlibs
added a commit
to staticlibs/duckdb-odbc
that referenced
this pull request
Jul 3, 2025
This is a backport of the PR duckdb#169 to `v1.3-ossivalis` stable branch. This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
staticlibs
added a commit
to duckdb/duckdb-odbc
that referenced
this pull request
Jul 3, 2025
This is a backport of the PR #169 to `v1.3-ossivalis` stable branch. This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
staticlibs
added a commit
to staticlibs/duckdb
that referenced
this pull request
Jul 4, 2025
Note: this PR is a draft, please do not merge. This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch.
staticlibs
added a commit
to staticlibs/duckdb
that referenced
this pull request
Jul 5, 2025
Note: this PR is a draft, please do not merge. This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch.
staticlibs
added a commit
to staticlibs/duckdb
that referenced
this pull request
Jul 5, 2025
This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch. Testing: it was checked in manual CI runs, that added unit test run actually causes a crash when `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` is not used.
staticlibs
added a commit
to staticlibs/duckdb
that referenced
this pull request
Jul 6, 2025
This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch. Testing: it was checked in manual CI runs, that added unit test run actually causes a crash when `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` is not used.
staticlibs
added a commit
to staticlibs/duckdb
that referenced
this pull request
Jul 9, 2025
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` preprocessor definition to Python wheel builds on Windows. For details see duckdb#17991, where the same definition was added for CLI builds. Fixes: duckdb#17971
staticlibs
added a commit
to staticlibs/duckdb
that referenced
this pull request
Jul 9, 2025
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` preprocessor definition to Python wheel builds on Windows. For details see duckdb#17991, where the same definition was added for CLI builds. Fixes: duckdb#17971
Mytherin
added a commit
that referenced
this pull request
Jul 10, 2025
carlopi
added a commit
to duckdb/vcpkg-duckdb-ports
that referenced
this pull request
Jul 10, 2025
carlopi
pushed a commit
to carlopi/duckdb
that referenced
this pull request
Jul 10, 2025
This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch. Testing: it was checked in manual CI runs, that added unit test run actually causes a crash when `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` is not used.
carlopi
added a commit
to duckdb/vcpkg-duckdb-ports
that referenced
this pull request
Jul 10, 2025
carlopi
pushed a commit
to carlopi/duckdb
that referenced
this pull request
Jul 10, 2025
This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch. Testing: it was checked in manual CI runs, that added unit test run actually causes a crash when `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` is not used.
carlopi
pushed a commit
to carlopi/duckdb
that referenced
this pull request
Jul 14, 2025
This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch. Testing: it was checked in manual CI runs, that added unit test run actually causes a crash when `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` is not used.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On Windows the
constexpr
constructor ofstd::mutex
, that was supposed to be there since C++11, was not implemented until VS2022. Its implementation has required to use Slim Reader/Writer (SRW) Locks (ref) that are only supported since Window 7, but VS2019 was still supporting Windows Vista as a target (more details from SO).The implementation of
constexpr std::mutex
in MSVC has required the ABI breakage in C++ STL that was eventually added in VS2022 17.10 (commit). This commit has introduced the macro_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
that can be defined to stay ABI compatible with older versions of C++ stdlib. Thus the binaries built with VS2022 17.10 or later and without this macro cannot be run with older versions of C++ stdlibmsvcp140.dll
even if they do not useconstexpr std::mutex
- any mutex usage will crash with something like this (more examples and comments from MSFT):This PR adds the
_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
macro definition to Windows builds assuming that we are not going to useconstexpr
constructor ofstd::mutex
and we want to be able to run withmsvcp140.dll
while being compiled with newer toolchains.Note, that running binaries, that were built against
msvcp140.dll
version14.40+
, in environment with earlier versionsmsvcp140.dll
is not officially supported by MSFT (ref). But we don't really have a choice here (unless we want to keep DuckDB itself on VS2019). Extensions (which build should include the engine CMake file being update by this PR) are going to be loaded though JDBC into JVM processes. As of mid 2025, OpenJDK builds from some of major vendors (e.g. Amazon Corretto), including the latest stable JDK 24 (released in March 2025) are still using VS2019 (likely the topic of this issue is one of the reasons for that). And all these JDKs include a vendored copy ofmsvcp140.dll
version14.29
. Due to the way, how Windows shared lib loader works, this vendored C++ stdlib will be loaded by the JVM instead of any system one. And then later when the JVM will load DuckDB extensions shared libs through JDBC - these extensions will also use this pre-loaded version of C++ stdlib, as we do not do static linking for it. In general, LTS JDK versions have 10+ years of production support (for example, JDK 6 released in late 2006 is still supported by some vendors). And even if later updates of LTS JDKs (11, 17, 21, 24 etc) will move to a newer version of MSVC toolchain - the old JDK binaries are going to be still in use for a long time.Thus this change is proposed as a permanent change - not a temporary workaround.
Testing: additional test run of
unittest.exe
is added that usesmsvcp140.dll
from VS2019 instead of the system-provided one.Fixes: #17971
Edit: added
wget
installation on Windows CI, removed "1.3" labels as this PR is intended to be the mainline one whenv1.3-ossivalis
will be merged into themain
branch later.