Determine if the current thread has low I/O priority

Posted by Magnus Hoff on Stack Overflow See other posts from Stack Overflow or by Magnus Hoff
Published on 2010-05-19T08:57:01Z Indexed on 2010/05/19 9:00 UTC
Read the original article Hit count: 279

Filed under:
|
|

I have a background thread that does some I/O-intensive background type work. To please the other threads and processes running, I set the thread priority to "background mode" using SetThreadPriority, like this:

SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN);

However, THREAD_MODE_BACKGROUND_BEGIN is only available in Windows Server 2008 or newer, as well as Windows Vista and newer, but the program needs to work well on Windows Server 2003 and XP as well. So the real code is more like this:

if (!SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN)) {
    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);
}

The problem with this is that on Windows XP it will totally disrupt the system by using too much I/O. I have a plan for a ugly and shameful way of mitigating this problem, but that depends on me being able to determine if the current thread has low I/O priority or not.

Now, I know I can store which thread priority I ended up setting, but the control flow in the program is not really well suited for this. I would rather like to be able to test later whether or not the current thread has low I/O priority -- if it is in "background mode".

GetThreadPriority does not seem to give me this information.

Is there any way to determine if the current thread has low I/O priority?

© Stack Overflow or respective owner

Related posts about win32

Related posts about c++