I was wondering how to use the scheduling mechanisms in Linux kernel with multiple threads, and I saw that sched_yield() system call can send the current thread to the end of the process queue. Since SCHED_OTHER is the default scheduler policy, the manual doesn't recommend to use this system call while using SCHED_OTHER because it is intended to be used with real time scheduling policies (man 2 sched_yield) and is unspecified with SCHED_OTHER:
sched_yield() is intended for use with real-time scheduling policies (i.e., SCHED_FIFO or SCHED_RR). Use of sched_yield() with nondeterministic scheduling policies such as SCHED_OTHER is unspecified and very likely means your application design is broken.
However, I saw this page from the RedHat documentation saying that sched_yield() shouldn't be used with real time tasks:
The sched_yield system call is used by a thread allowing other threads a chance to run. Often when sched_yield is used, the thread can go to the end of the run queues, taking a long time to be scheduled again, or it can be rescheduled straight away, creating a busy loop on the CPU. The scheduler is better able to determine when and if there are actually other threads wanting to run. Avoid using sched_yield on any RT task.
So how do I should use the sched_yield() system call ? What this would do with a SCHED_OTHER or a SCHED_FIFO policy ? From what I understood is that with a SCHED_FIFO policy, the thread won't be interrupted unless a sched_yield(), and then the second requested thread will be processed unless it end, and the first thread will continue when all the thread queue has been processed (with a FIFO behavior).
Also, what this system call would do with the SCHED_RR policy, since all the threads are partially processed each quantum ?