Search code examples
linuxmultithreadingscheduled-tasksreal-time

yielding from linux kernel


I have a real-time thread in Linux (3.4). Under certain conditions, I want it to relinquish control to other threads with the same priority, even if it hasn't finished using up its current timeslice. I was thinking of using the following code:

if (condition) {
    resched_task();
    cond_resched();
}

however, I don't see anyone else in the code doing this, making me think there's some other (better?) way of doing this. Is there a standard way to do this?


Solution

  • You can use the sched_yield() function to yield the rest of your time slice, as discussed here.

    sched_yield() causes the calling thread to relinquish the CPU. The thread is moved to the end of the queue for its static priority and a new thread gets to run.