Why is my program resource intensive even though I set THREAD_MODE_BACKGROUND_BEGIN?

I have a program structured as follows, and this is a massive processor boss. IO is slowing down for the whole system, I can hardly move the mouse pointer ...

... why? I thought THREAD_MODE_BACKGROUND_BEGIN should prevent this?

#pragma omp parallel { SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN); #pragma omp for for (...) { doTruckLoadsOfComputation(); if (omp_get_thread_num()==0) doTinyAmountOfIO(); //progress indicator } SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_END); } 

UPDATE:

Adding SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL); fixes the problem with starting the processor, but the question is still, why is not enough one background mode?

+5
source share
1 answer

It's too long to comment

You have simpler alternatives: START /BELOWNORMAL <yourexe> can start any arbitrary process with a lower priority, without changing the source code.

If you want to do this from within an application, a Job object is a much better alternative. Use JOBOBJECT_CPU_RATE_CONTROL_INFORMATION to JOBOBJECT_CPU_RATE_CONTROL_INFORMATION control how much a processor can use your application. The most important benefit of JOBs and thread attachment is that work restrictions apply to the whole process and to any process generated by a controlled process.

0
source

Source: https://habr.com/ru/post/1246075/


All Articles