C++ program using <thread>

Mark Geisert mark@maxrnd.com
Fri Jun 11 05:52:02 GMT 2021

Hi André,

André Bleau via Cygwin wrote:
> Hi all,
> I have a small C++ program using <thread>. Mainly, I have a series of long tasks for which I can use a chosen number of threads. I create a given number of instances of the std::thread class, each executing the same function but with different data. After launching the threads, my program waits for the results by calling thread.join() on each thread. Some threads finish sooner than others, depending on the data they process.
> I have 16 cores with hyperthreading, so 32 virtual cores. I tried a big run with 63 threads.
> If I compile as a Cygwin program with g++ 10.2.0, when the program runs with 63 threads the CPU load for the program never exceeds 6 or 7%. It remains constants when some of the threads finish, unless the number of threads remaining goes down to about 4.
> If I compile as a Mingw program with x86_64-w64-mingw32-c++ 10.2.0, when the program runs with 63 threads the CPU load for the program reaches 98% then gradually diminishes as threads finish their task.
> Needless to say, the total running time for the Mingw version is much shorter.
> So, is there a limit to the CPU load that a threaded Cygwin program can get? If yes, how can it be changed?

Fascinating report; thanks!  I doubt there's an intentional limit, but perhaps 
there is some difference between the Cygwin and MinGW environments that explains 
the symptoms.  No idea at this point though.

Oh, does your program set process or thread affinity anywhere?

Would you be able to post the source of your test program, or provide it to me by 
private email?  I would run my cygmon profiler on it to look for clues.  There 
have been several other reports of multi-threaded programs taking far too long to 
complete, but the reports came in as possibly malloc-related issues so they may 
differ from yours.  But cygmon has found something troubling in those cases that 
I'm still investigating.


More information about the Cygwin mailing list