Question

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?

Was it helpful?

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.

OTHER TIPS

The question sounds like it's asking about kernel programming but the accepted answer is a function user mode API sched_yield(). I think the kernel answer to this question is schedule()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top