meganz / mingw-std-threads

Standard threads implementation currently still missing on MinGW GCC on Windows
BSD 2-Clause "Simplified" License
439 stars 137 forks source link

Upstream into MinGW? #57

Open ryao opened 5 years ago

ryao commented 5 years ago

Is there any effort being made to upstream this into MinGW?

nmcclatchey commented 5 years ago

I am not currently aware of any such effort. We have reached a point where such an effort would be reasonable, but such an effort was not yet sparked.

That said, there are a few features specified by the C++ standard that are not yet implemented by this library:

There are also various desirable features that have not yet been implemented, but which would be good to add for MinGW

ryao commented 5 years ago

@nmcclatchey The lack of mutex and condition-variable support in the win32 thread model in mingw has been an on-going issue for users trying to build DXVK in Gentoo and other distributions. In Gentoo, at least, it is possible after jumping through some hoops to build a posix thread model toolchain, but the details of how that works does not play nicely with system updates. If I recall correctly, our package manager treats builds as being idempotent and the way that the posix thread model toolchain is built is bootstrapped, which is not idempotent friendly.

I have a WIP DXVK branch that uses your code to make the builds work, but the DXVK author does not like the size of the headers and would rather that we upstream this into mingw:

https://github.com/ryao/dxvk/tree/win32-thread-model-support

I am not sure how many cycles that I have to dedicate to this, but would it be alright if I tried kicking off the upstream process by getting a branch for a possible mingw pull request together? I expect that MinGW would require signed off from mega nz (as do most well established projects), so there would be no point in starting that unless you are willing to provide signed off. I would rather find out now than after I found some time to put into preparing a branch to use in a hypothetical pull request.

nmcclatchey commented 5 years ago

@ryao Though I will whole-heartedly support you in upstreaming this, I am not affiliated with Mega NZ (I just contribute to this library). I believe that the correct person with whom to discuss the necessary dual-licensing is @alxvasilev .

Please keep me in the loop regarding the MinGW-w64 pull request. There are several aspects of this library that can be streamlined if a minimal MinGW version can be assumed (including using __invoke, using __is_invocable, reducing code duplication, etc.).

alxvasilev commented 5 years ago

In fact there was an idea, long time ago, to include this library in mingw-w64, which was discussed here https://sourceforge.net/p/mingw-w64/mailman/message/33144181/ To facilitate the inclusion I changed the license, however no further actions were taken by the community. Some time later someone raised the question again here https://sourceforge.net/p/mingw-w64/mailman/message/33592988/ and one of the answers was that no one had offered a pull request to include it. In case you are willing to do that, I will support it. There is one more thing though - I am not completely sure if this project takes the optimal approach to implementing full thread support in both C++11 and C11, and with minimal effort. Maybe implementing a native win32 port of the gthreads API (on top of which all thread support in gcc is implemented) would be a more rational solution (albeit somewhat less efficient due to the additional layer).

ryao commented 5 years ago

@alxvasilev The current approach used here is vastly preferable to the status quo, which is causing problems on Gentoo when cross compiling Windows software like DXVK and D9VK. Thanks for being open to moving this forward. I will see what I can do in my spare time and get back to you in a few weeks.

alxvasilev commented 5 years ago

Great! Thanks in advance for your effort!

ThePirate42 commented 3 years ago

Have there been any news on this?

alxvasilev commented 3 years ago

No, unfortunately.

xtemp09 commented 2 years ago

Can the venerable owner of this repository elaborate the following sentence:

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.

Is it going upstream?

alxvasilev commented 2 years ago

There are two versions of mingw-w64, based on threading support - one of them uses a pthread emulation layer for access to all threading functionality of Windows. Namely that version has std::thread, std::mutex, etc classes. The drawback is low performance.

lhmouse commented 2 years ago

Do you have any interest in https://github.com/lhmouse/mcfgthread/ which implements a new thread model that is both efficient and standard-compliant. Prebuilt binaries are available at https://gcc-mcf.lhmouse.com/.