Hi,
I see the code for creating SCHED_FIFO thread in audio hal:
//create rx task, use real time thread.
pthread_attr_init(&attr);
pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
schParam.sched_priority = 3;
pthread_attr_setschedparam(&attr, &schParam);
adev->b_sco_rx_running = true;
ret = pthread_create(&tid_sco_rx, &attr, sco_rx_task, (void *)adev);
It should be fine to imitate this code
In our android audio hal, 2 threads with SCHED_FIFO type will be also created.
[note]
SCHED_FIFO implements a simple, first-in-first-out scheduling algorithm, it does not use time slices.
The SCHED_FIFO level process is scheduled before any SCHED_NORMAL level process. Once a SCHED_FIFO level process is in an executable state, it will continue to execute until it blocks itself or explicitly releases the processor; it is not based on time slices and can be executed forever. Only the higher priority SCHED_FIFO or SCHED_RR task can preempt the SCHED_FIFO task. If there are two or more SCHED_FIFO-level processes, they will execute in turn, but will give up again when they are willing to give up the processor.
As long as a SCHED_FIFO-level process is executing, other lower-level processes can only have a chance to execute after it ends.
Hope this information is helpful to you.
Have a nice day!
B.R,
Weidong