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

  • Home
  • SEARCH
  • 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 6182579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:13:20+00:00 2026-05-24T01:13:20+00:00

Another newbie question: In the following code, what if the thread is preempted after

  • 0

Another newbie question:

In the following code, what if the thread is preempted after calling ‘set_current_state’ but before ‘schedule’ is called. When the code is scheduled again, does it start from ‘schedule’ call and is removed from the run queue? Or the ‘schedule’ call is ignored this time and starts from the set_current_state(TASK_RUNNING) statement?

{
...
set_current_state(TASK_INTERRUPTIBLE); /* suppose thread is preempted just after this function call */
schedule();
set_current_state(TASK_RUNNING);
...
} 
  • 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-24T01:13:21+00:00Added an answer on May 24, 2026 at 1:13 am

    Here’s (more or less) what will happen if involuntary preemption happens after the first line and before the second:

    1. The scheduler will run (scheduler() function from sched.c) – since this is what being preempted mean.

    2. Since your task is marked as not runnable, the scheduler will remove it from the run queue and will pick another task.

    3. Now your task will not be scheduled until something external will mark it as runnable again. This might happen due to a signal sent to the task or, assuming the task is queued in a wait queue, due to the event the wake queue belongs to happening, but something external MUST mark the task as runnable again or it will never be scheduled. This is why if you look at the wait queue code, it first put the task on the wait queue and only then does something similar to your code.

    4. When your task is marked as runnable, at some point the scheduler will pick it and will context switch into the task code.

    5. Then the schedule() function will get called. In all likelihood, the scheduler is going to pick the same task yet again, since it has just been picked by it as most eligible for running and it is not likely that this have changed.

    6. On the way back from the scheduler, the last set_current_state will basically be a no op, since the task by this time is already marked as runnable in this scenario.

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

Sidebar

Related Questions

I have another newbie Python question. I have the following piece of code that
Well, I know this is another newbie question but I'm very frustrated and I'm
another iPhone newbie question... I have the following: NSPersistentStoreCoordinator NSManagedObjectContext NSManagedObjectModel Is it possible
I've got another newbie question. I've written a piece of code that converts a
Another newbie question from me. Just checking whether my code below is possible. I.e
In another question on SO I answered with code like the one below and
I have a newbie question about the following: - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
Sorry another newbie question that I couldn't seem to find an answer to on
this is a bit of a newbie question but I can't seem to find
I have another newbie question; lets say I have a set of numbers graph_val

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.