This is a temporary URL until I can be bothered setting up a blog.

Enabling std::thread and friends in MinGW GCC 4.7

23 August 2012, 5:33 UTC

This patch enables the C++11 thread, mutex and future features using pthread-w32 as the implementation (which comes bundled with MinGW).

This assumes you are using the official MinGW distribution.
If you are applying this patch to a version of MinGW GCC later than 4.7, you should examine and apply the patches rather than using the zip file.

NOTE: "libstdthread" is a completely unofficial name, so should only be part of your local build command.
On gcc toolchains already supporting threads, it is a part of libstdc++ and linked by default for C++ projects.

Update, 14 September 2012:

All patches here are released in to the public domain, and free for use for any purpose.

Please note that this patch cannot enable thread safety throughout libstdc++, as it is applied post-build. This means some conforming programs that use standard library facilities from multiple threads may result in unexpected behaviour. It has also been known to cause problems with other libstdc++ components, breaking std::fstream being one noted example.

You may prefer to look in to the mingw-w64 stdthread branch, which is working to enable std::thread support properly in MinGW.

Tags: MinGW, C++, libstdc++, thread

Author: Julian Smythe