Skip to content

Use fallback ThreadImpl for mingw#1351

Merged
Aidan63 merged 2 commits into
HaxeFoundation:masterfrom
tobil4sk:fix/threads-mingw
Jul 1, 2026
Merged

Use fallback ThreadImpl for mingw#1351
Aidan63 merged 2 commits into
HaxeFoundation:masterfrom
tobil4sk:fix/threads-mingw

Conversation

@tobil4sk

@tobil4sk tobil4sk commented Jun 25, 2026

Copy link
Copy Markdown
Member

Possibly a regression from: #1336.

Mingw is has a pthread handle as std::thread::native_handle_type so it cannot be used in APIs that expect HANDLE:

Error: /.../hxcpp/src/hx/thread/ThreadImpl.win32.cpp: In member function ‘virtual String hx::thread::ThreadImpl_obj::getName()’:
/.../hxcpp/src/hx/thread/ThreadImpl.win32.cpp:14:52: error: invalid conversion from ‘std::thread::native_handle_type’ {aka ‘long long unsigned int’} to ‘HANDLE’ {aka ‘void*’} [-fpermissive]
   14 |         auto result = GetThreadDescription(native->handle, &buffer);
      |                                            ~~~~~~~~^~~~~~
      |                                                    |
      |                                                    std::thread::native_handle_type {aka long long unsigned int}
In file included from /usr/x86_64-w64-mingw32/include/winbase.h:29,
                 from /usr/x86_64-w64-mingw32/include/windows.h:70,
                 from /.../hxcpp/src/hx/thread/ThreadImpl.win32.cpp:2:
/usr/x86_64-w64-mingw32/include/processthreadsapi.h:367:58: note: initializing argument 1 of ‘HRESULT GetThreadDescription(HANDLE, WCHAR**)’
  367 |   WINBASEAPI HRESULT WINAPI GetThreadDescription (HANDLE hThread, PWSTR *ppszThreadDescription);
      |                                                   ~~~~~~~^~~~~~~
/.../hxcpp/src/hx/thread/ThreadImpl.win32.cpp: In member function ‘virtual void hx::thread::ThreadImpl_obj::setName(const String&)’:
/.../hxcpp/src/hx/thread/ThreadImpl.win32.cpp:39:52: error: invalid conversion from ‘std::thread::native_handle_type’ {aka ‘long long unsigned int’} to ‘HANDLE’ {aka ‘void*’} [-fpermissive]
   39 |         auto result = SetThreadDescription(native->handle, name.wchar_str(&buffer));
      |                                            ~~~~~~~~^~~~~~
      |                                                    |
      |                                                    std::thread::native_handle_type {aka long long unsigned int}
/usr/x86_64-w64-mingw32/include/processthreadsapi.h:366:58: note: initializing argument 1 of ‘HRESULT SetThreadDescription(HANDLE, PCWSTR)’
  366 |   WINBASEAPI HRESULT WINAPI SetThreadDescription (HANDLE hThread, PCWSTR lpThreadDescription);
      |                                                   ~~~~~~~^~~~~~~
/.../hxcpp/src/hx/thread/ThreadImpl.win32.cpp: In constructor ‘hx::thread::ThreadImpl_obj::Native::Native()’:
/.../hxcpp/src/hx/thread/ThreadImpl.win32.cpp:55:81: error: invalid conversion from ‘HANDLE’ {aka ‘void*’} to ‘std::thread::native_handle_type’ {aka ‘long long unsigned int’} [-fpermissive]
   55 | hx::thread::ThreadImpl_obj::Native::Native() : thread(), handle(GetCurrentThread()) {}
      |                                                                 ~~~~~~~~~~~~~~~~^~
      |                                                                                 |
      |                                                                                 HANDLE {aka void*}

@Aidan63

Aidan63 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Could we use c++ casts instead of the old c style ones? Also, is there some sort of mingw define to put these changes behind? The msvc stl returns a HANDLE for the native thread type so it don't need any casting.

@tobil4sk

Copy link
Copy Markdown
Member Author

The msvc stl returns a HANDLE for the native thread type so it don't need any casting.

Hm, that makes me think maybe I'll need to look into this more properly to make sure this fix is correct. Perhaps the actual problem is that the native handle on mingw is a pthread handle, in which case the cast is not a sufficient fix.

@Aidan63

Aidan63 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

From a quick google it seems mingw provides two threading implementations, a posix one (the default) and a win32 one, but only the posix one provides a C++11 threading implementation.

boostorg/fiber#172

There are some third party projects which provides C++11 threading support for the win32 implementation though. https://github.com/meganz/mingw-std-threads

So it does seem like this change just silences the warning but it won't actually work as it's just casting a pthread handle to a win32 HANDLE. This has done nothing to change my opinion that mingw and it's ilk are a massive nightmare and not worth it.

tobil4sk added 2 commits July 1, 2026 10:05
Mingw has a pthread handle as the native thread, so we cannot use it
with the win32 api.
This is msvc specific, so it should only be added for msvc builds, not
globally in the haxe-target.xml file. It is already added for msvc
builds in the msvc-toolchain file.
@tobil4sk tobil4sk force-pushed the fix/threads-mingw branch from d6ed39a to 3a60b4d Compare July 1, 2026 09:05
@tobil4sk tobil4sk changed the title Add missing casts for ThreadImpl.win32 with mingw Use fallback ThreadImpl for mingw Jul 1, 2026
@tobil4sk

tobil4sk commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

I made it fall back to the noop implementation on mingw which seems like the easiest fix, given that this feature is not fully supported anyway.

I've also removed the -D_CRT_SECURE_NO_DEPRECATE flag from haxe-target.xml, since it was being added globally but is only relevant to windows msvc builds and it is already added by msvc-toolchain.xml. (It was already removed in #1160, but perhaps reintroduced in #1336 due to a merging accident.)

@Aidan63 Aidan63 merged commit 80461f1 into HaxeFoundation:master Jul 1, 2026
133 checks passed
@tobil4sk tobil4sk deleted the fix/threads-mingw branch July 1, 2026 09:46
@tobil4sk

tobil4sk commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants