2
votes

I'm using MinGW_W64, and I'm having trouble deciding how to move forward with the "threading" option. I can use either posix threads, or win32 threads. So far I've been using C++11's "std::thread" for my threading (which requires the posix threads option), and I really like the interface doing things this way. However, I've read from multiple sources that posix threads are significantly slower than win32 threads, and performance is a big concern for me.

My project will eventually be multi-platform, but for now my primary development machine is running Windows 7.

My question is: Are MinGW_W64's posix threads slower than the win32 threads? If so, how would I go about writing a wrapper that would let me using an std::thread-like interface but using win32 threads under the hood (or finding such a wrapper if someone's already written one)?

1
pthreads on windows is probably pthreads-win32 which just exposes the pthread API but uses win32 threads under the hood. - Rapptz
Also, if you're wide open to options, VS2013+ has full implementation of C++11's std::thread specification, and uses native threads, mutexes, condition variables, etc. I'm begging my employer to allow us to move off of VS2005/VS2010, with that being one of the reasons (that and C++11, even MS's pitiful implementation, is better than C++98 any day of the week and twice on sundays). - WhozCraig
I'm actually using VS2013 right now, but I'm looking to switch for a number of reasons (firstly, I can't allocate aligned classes on the stack). - Haydn V. Harach
Do any of these sources give any explanation for why or under what circumstances "POSIX threads are slower"? On the face of it, it doesn't seem reasonable; a thread is just a thread, the CPU is handling the instructions in the same way no matter what. - Harry Johnston
Well, since you read "multiple sources" (URL?) that POSIX threads are slower than win32 threads, check those sources for a precise measurement or benchmark that proves their claim. For the record, I could imagine different threading implementations to differ in performance during startup and for inter-thread communication (mutexes etc), but the "normal" operations inside shouldn't differ. - Ulrich Eckhardt

1 Answers

3
votes

There is already a lightweight native implementation of std::thread and sync primitives for MinGW, implemented in pure WINAPI: https://github.com/meganz/mingw-std-threads

It's a header-only lib and should work with any version of MinGW that has proper C++11 support.