Skip to content
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

Windows: use native thread API instead of pthread #403

Open
vtorri opened this issue Apr 11, 2024 · 4 comments
Open

Windows: use native thread API instead of pthread #403

vtorri opened this issue Apr 11, 2024 · 4 comments

Comments

@vtorri
Copy link
Contributor

vtorri commented Apr 11, 2024

On Windows, mingw project provides winpthread forPOSIX thread interface. But according to the devs:

  • winpthread was written for the Windows port of gcc
  • winpthread is slower than native API (because of all the code needed to have a POSIX interface).

would it be possible to have such implementation (supported versions of Windows : >= Vista, as for example, conditions are implemented since Vista) ?

thank you

@Jovasa
Copy link
Member

Jovasa commented Apr 11, 2024

We have our own wrapper for c++ threads API here https://github.com/ultravideo/kvazaar/tree/master/src/threadwrapper that is used by the MSVC build, would using it also in mingw suffice? It should be fairly simple to enable on CMakeLists
This without getopt.c

kvazaar/CMakeLists.txt

Lines 212 to 214 in 9eed4c3

if(MSVC)
list(APPEND CLI_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/extras/getopt.c ${CMAKE_CURRENT_SOURCE_DIR}/src/threadwrapper/src/pthread.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/threadwrapper/src/semaphore.cpp)
endif()

and this
target_include_directories(kvazaar PUBLIC src/threadwrapper/include)

should be included with MSYS/MINGW

and these excluded

kvazaar/CMakeLists.txt

Lines 243 to 245 in 9eed4c3

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(kvazaar PUBLIC Threads::Threads)

At least in theory it should work, though I haven't tested it.

@vtorri
Copy link
Contributor Author

vtorri commented Apr 11, 2024

ok, you use the c++11 thread API. That means:

  • with unix : usage of pthread
  • with cl.exe (Windows compiler) : usage of native Win32 API
  • with mingw : usage of winpthread, wich is a port of pthread on Windows as I said

so the current implementation will work (i can see that libkvazaar-7.dll is linked against libwinpthread.dll with mingw). It's just that i would have prefered a native implementation with mingw. But it is some work

@Jovasa
Copy link
Member

Jovasa commented Apr 12, 2024

Unfortunately I won't have time to work on this but if you want to do it I can accept a pull request.

@vtorri
Copy link
Contributor Author

vtorri commented Apr 12, 2024

if i have time, i'll look at it

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

No branches or pull requests

2 participants