c++ - Effects of sched_yield() from a thread running with SCHED_RR scheduling policy -
i have process under linux consisting of 2 threads, 1 producer , 1 consumer. simplicity, assume process running in system on single-core, single-cpu architecture.
the producer created first , manually assigned sched_rr
scheduling policy sched_setscheduler(0, sched_rr, ¶ms)
. after time, consuming thread created too. it's created after sched_setscheduler
has been called producer, not have same sched_rr
scheduling policy set.
under situation, trying understand effects of sched_yield()
producer (once 1 element produced).
there 2 possibilities, not sure 1 true:
- the consumer may scheduled execution before producer runs again
- the consumer cannot scheduled execution because not being run
sched_rr
scheduling policy and producer did not complete assigned quantum time or did notsleep
. in caseyield()
might have negative effects, it's called nothing.
while i'm not sure happens in practice, formally sched_yield
not allow lower-priority thread run in case; it's yielding same-priority threads.
you should using condition variables or other proper synchronization mechanism ensure consumer gets run (the producer should pthread_cond_wait
on predicate queue above fullness threshold or similar) rather trying sleep/yield-based scheduling.
Comments
Post a Comment