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, &params). 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:

  1. the consumer may scheduled execution before producer runs again
  2. the consumer cannot scheduled execution because not being run sched_rr scheduling policy and producer did not complete assigned quantum time or did not sleep. in case yield() 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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -