mingw-std-threads
=================
Implementation of standard C++11 threading classes, which are currently still missing on MinGW GCC.
Target Windows version
----------------------
This implementation should work with Windows XP (regardless of service pack), or newer.
The library automatically detects the version of Windows that is being targeted (at compile time), and selects an implementation that takes advantage of available Windows features.
In MinGW GCC, the target Windows version may optionally be selected by the command-line option `-D _WIN32_WINNT=...`.
Use `0x0600` for Windows Vista, or `0x0601` for Windows 7.
See "[Modifying `WINVER` and `_WIN32_WINNT`](https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt)" for more details.
Usage
-----
This is a header-only library. To use, just include the corresponding `mingw.xxx.h file`, where `xxx` would be the name of the standard header that you would normally include.
For example, `#include "mingw.thread.h"` replaces `#include <thread>`.
A `CMakeLists.txt` has also been provided. You can add it to your project by using `add_subdirectory()`, and then this library can be added as your targets' dependency by using `target_link_libraries(YOUR_TARGET PRIVATE mingw_stdthreads)`. By default it just adds a include path, allowing you to include headers using angle brackets (for example `#include <mingw.thread.h>`). But you can also provide options to let it generate "std-like" headers (see next paragraph).
Using "std-like" headers
------------------------
Probably you don't really want to replace all your includes from `#include <header>` to `#include "mingw.header.h"`. So if you are using GCC or clang, here are some ways to make you happy :)
With CMake, you just need to turn on the option `MINGW_STDTHREADS_GENERATE_STDHEADERS` before adding mingw-stdthreads, something like this:
```CMake
option(MINGW_STDTHREADS_GENERATE_STDHEADERS "" ON)
add_subdirectory(mingw_stdthreads)
target_link_libraries(${TARGET} PRIVATE mingw_stdthreads)
```
When CMake generates project files, headers named in the "standard header" way will be generated and added to your include path. Then you can avoid stuffs like `mingw.thread.h`, and keep using `#include <thread>` like always. In addition, `MINGW_STDTHREADS_GENERATED_STDHEADERS` will be defined, you can use this macro to check if those generated headers are actually available.
If you aren't using CMake, you can use one of the three scripts inside [utility_scripts](utility_scripts) directory to manually generate those "std-like" headers. Note that this requires Microsoft Power Shell, so if you are cross-compiling, you would need to install Power Shell.
Compatibility
-------------
This code has been tested to work with MinGW-w64 5.3.0, but should work with any other MinGW version that has the `std` threading classes missing, has C++11 support for lambda functions, variadic templates, and has working mutex helper classes in `<mutex>`.
Switching from the win32-pthread based implementation
-----------------------------------------------------
It seems that recent versions of MinGW-w64 include a Win32 port of pthreads, and have the `std::thread`, `std::mutex`, etc. classes implemented and working based on that compatibility layer.
You could use the built-in pthread implementation of Mingw by using the posix compiler, eg: `x86_64-w64-mingw32-g++-posix` (for Windows 64-bit).
That is a somewhat heavier implementation, as it relies on an abstraction layer, so you may still want to use this implementation for efficiency purposes.
Unfortunately you can't use this library standalone and independent of the system `<mutex>` headers, as it relies on those headers for `std::unique_lock` and other non-trivial utility classes.
In that case you will need to edit the `c++-config.h` file of your MinGW setup and comment out the definition of _GLIBCXX_HAS_GTHREADS.
This will cause the system headers not to define the actual `thread`, `mutex`, etc. classes, but still define the necessary utility classes.
Why MinGW has no threading classes
----------------------------------
It seems that for cross-platform threading implementation, the GCC standard library relies on the gthreads/pthreads library.
If this library is not available, as is the case with MinGW, the classes `std::thread`, `std::mutex`, `std::condition_variable` are not defined.
However, various usable helper classes are still defined in the system headers.
Hence, this implementation does not re-define them, and instead includes those headers.
没有合适的资源?快使用搜索试试~ 我知道了~
mingw-std-threads-master
共17个文件
h:7个
txt:3个
bat:2个
需积分: 5 0 下载量 110 浏览量
2024-03-13
17:26:10
上传
评论
收藏 42KB ZIP 举报
温馨提示
替代MinGW GCC thread 头文件的库,解决c++11及以上版本,在window下引用thread头文件不能正常编译的问题 适用人群:window 下c++开发 mingw-std-threads-master介绍 mingw-std-threads-master是一个为MinGW(Minimalist GNU for Windows)环境提供的标准线程库实现。MinGW是一个开源项目,它提供了在Windows平台上使用GNU工具集(如GCC)进行软件开发的能力,使得开发者能够利用GNU工具链的强大功能和跨平台特性。 在C++中,线程是并行计算的核心概念,它允许程序同时执行多个任务,从而充分利用多核处理器的性能。然而,C++标准库中的线程支持在不同的编译器和平台上可能有所差异,特别是在Windows平台上,标准线程库的实现可能并不完善或存在限制。
资源推荐
资源详情
资源评论
收起资源包目录
mingw-std-threads-master.zip (17个子文件)
mingw-std-threads-master
CMakeLists.txt 1KB
cmake_stdheaders_generator
CMakeLists.txt 3KB
template.cpp 467B
mingw.thread.h 12KB
mingw.future.h 32KB
LICENSE 1KB
utility_scripts
generate_std_like_headers_interactive.bat 86B
generate_std_like_headers.bat 92B
Generate-StdLikeHeaders.ps1 8KB
tests
CMakeLists.txt 887B
tests.cpp 18KB
mingw.condition_variable.h 20KB
mingw.invoke.h 3KB
mingw.latch.h 3KB
mingw.mutex.h 16KB
README.md 4KB
mingw.shared_mutex.h 15KB
共 17 条
- 1
资源评论
前鼻音太阳熊
- 粉丝: 394
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功