This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTX v4 thread starvation

I believe I've found a thread starvation problem in RTX v4.x

If you have a two threads runnings at the same priority and then up the priority on one thread to do some important work, if the higher priority thread uses more than one time slice, then lowers its priority to that of the other thread it will continue to run until it blocks, even though it should be round robin with the other same priority thread. Here's the problem:

__weak void rt_chk_robin (void) {
  /* Check if Round Robin timeout expired and switch to the next ready task.*/
  P_TCB p_new;

  if (os_robin.task != os_rdy.p_lnk) {
    /* New task was suspended, reset Round Robin timeout. */
    os_robin.task = os_rdy.p_lnk;
    os_robin.time = (U16)os_time + os_robin.tout - 1U;
  }
  if (os_robin.time == (U16)os_time) {
    /* Round Robin timeout has expired, swap Robin tasks. */
    os_robin.task = NULL;
    p_new = rt_get_first (&os_rdy);
    rt_put_prio ((P_XCB)&os_rdy, p_new);
  }
}


If the high priority thread passes the second check (runs beyond it's slice because it's the only runnable thread at that priority), it can then lower it's priority and never relinquish again because the first check won't be true until something causes the p_lnk to change (and os_time will be > os_robin.time).

Instead the second check should be (os_time - os_robin.time) > (os_robin.tout - 1U). This would allow round robin to do its job next tick.

I've reviewed RTX version 5 and this problem seems to be resolved.

Seth

Parents Reply Children
No data