lhmouse / mcfgthread

Cornerstone of the MOST efficient std::thread on Windows for mingw-w64
https://gcc-mcf.lhmouse.com/
Other
269 stars 28 forks source link

mcfgthread, gthread, pthead and linking #43

Closed Xeverous closed 4 years ago

Xeverous commented 4 years ago

I'm using the prebuild compiler from https://gcc-mcf.lhmouse.com on Windows and I'm not sure what my projects should link with. I have noticed there are mcfgthread-12.dll and libwinpthread-1.dll in compiler's installation directory. Should my programs link to both? Is any of these libraries dependent on another?

I have very little knowledge of threading implementation, only using C++ standard library API. Not sure what is missing when I get undefined reference to pthread_mutex_init which happened when I linked my program to libboost_filesystem.

Can you explain what-is-what/what-X-is-implementing-Y/what-X-depends-on-Y from mcfgthread, gthread, pthead, winpthread? What should I know and care about? I don't want to silently corrupt my executables by wrong compiler/linker options.

lhmouse commented 4 years ago

Those boost libraries are prebuilt ones maintained by MSYS2 which link against winpthreads.

Xeverous commented 4 years ago

Would be there any problem if I link my program (which uses mcfgthread) to these boost libraries which use winpthreads?

lhmouse commented 4 years ago

There wouldn't be as long as boost uses exclusively boost::thread, boost::mutex etc. (not the std ones). I haven't verified it though.

Xeverous commented 4 years ago

What is the reliation between mcfgthread, gthread, pthead, winpthread?

lhmouse commented 4 years ago

pthread is a specification that is part of POSIX unrelated to any operating system, which specifies the types and functions to manipulate threads. winpthreads is an implementation that conforms to the aforementioned specification on Windows.

gthread is a specification by GCC to provide types and functions which 0) are used to implement std::mutex, std::thread etc. in libstdc++ and 1) are also used in various other places in libgcc. mcfgthread is an implementation that conforms to the aforementioned specification that does not involve winpthreads.

Xeverous commented 4 years ago

That explains all, thanks.