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 8988919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:07:38+00:00 2026-06-15T22:07:38+00:00

I have a process which contain two threads. I want to schedule them based

  • 0

I have a process which contain two threads. I want to schedule them based on their priority(SCHED_RR policy). Let t1, t2 denote these threads, both having priority 1 (lowest) initially.

I want to make sure that my thread t1 is not preempted/rescheduled while it is doing critical task – so I boost its priority to maximum before the critical task and reduce it to the original value after the critical task:

thread_proc_t1() {
    while(1) {
        if(critical condition happens) {
            set_priority_max();
        }
        printf("t1");
        usleep(xxx);
        if(critical task finished ) {
            reset_priority();
        }
    }   
}

thread_proc_t2() {
    while(1) {
        printf("t2");
        usleep(xxx);
    }   
}

I expect the printf() commands in thread t2 not to be executed after I’ve called set_priority_max() in thread t1. But the output does contains prints from thread t2 also.

  1. Why is this the case?

  2. How can I solve this problem?

  • 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-06-15T22:07:41+00:00Added an answer on June 15, 2026 at 10:07 pm

    There’s no problem, this is expected behavior.

    First, if you have more than one core, then the priorities won’t matter if there are fewer ready-to-run threads than cores — each thread will get its own core.

    Second, your high-priority thread sleeps, which gives the lower-priority thread time to run.

    Third, your threads interact through the lock that protects standard output. The higher-priority thread can be waiting for that lock, allowing lower-priority threads to run.

    Please don’t try to use priorities this way. It adds massive complexity, hurts performance, and rarely accomplishes anything useful.

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

Sidebar

Related Questions

Let's say I have a list somewhere called majorPowers which contain these two lists:
I have a process which gives me continuously output in Screen. I want to
I have a process which has a notify method which receives as a parameter
I have a process which iterates through a bunch of ActiveRecord models, does some
I have a process x which uses system C function to start ntpd daemon.
We have a feed process which runs every day of the year. As part
I have a C++ process which has a thread that needs to send floats
I have a Spring Batch process which has following kind of code. <step id=step1
I have to do a background process which will perform some operations.. while this
I am currently trying to communicate a parent process which should have multiple children

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.