Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 788169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:19:07+00:00 2026-05-14T21:19:07+00:00

if (reader.is_lazy()) goto tldr; I have a background thread that does some I/O-intensive background

  • 0
if (reader.is_lazy()) goto tldr;

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 an 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”.

tldr:

GetThreadPriority does not seem to give me this information, it only gives the CPU priority.

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:19:08+00:00Added an answer on May 14, 2026 at 9:19 pm

    Well it fails if you’ve already set it to background mode. Could you, dependent on whether you would like it to be background processing, not just Set the priority to background begin and see if it fails?

    If you’d expect/want it not to be then you could test by calling background end.

    If thats not good to you you’d probably be best off just using Thread Local Storage to store whether it is in background mode or not.


    Edit by Magnus Hoff: This is how I ended up implementing it:

    bool has_low_io_priority() {
        if (SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN)) {
            // Seems we were able to enter background mode. That means we were
            // not in background mode from before.
            SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_END);
            return false;
        } else {
            DWORD err = GetLastError();
            if (err == ERROR_THREAD_MODE_ALREADY_BACKGROUND) return true;
            else return false; //< Background mode is not available at all
        }
    }
    

    Works well 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an text reader app that is designed to receive intent from Android
I have some code that uses deferred execution and lazy loading: public static IEnumerable<XElement>
There is a pagenumber property in flowdocument reader.But that property is readonly. Is there
Is it only for screen reader software? because browser renders both type of tags
The title is pretty self-explanatory: does anyone know of a (good) properties file reader
So, I'm feeding file data to an API that takes a Reader , and
So I have almost no iphone programming experience, yet I have found some basic
I have following code. The query take some 30 seconds to execute. I found
So, this does not necessarily have to do directly with the code itself, although
Imagine I have a SearchService layer that has a method to search all cars

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.