Queues and possible task priority problem

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Queues and possible task priority problem

    I have a simple application with three tasks:

    T1: producer task, puts some data to the queue. Producer priority is "1"
    T2: low priority consumer task, retrieves data from the queue. its priority is "2"
    T3: high priority consumer task, retrieves data from the queue. its priority is "3"

    It seems that if queue is empty, and T3 calls OS_Q_GetPtr() before T2, when T1 produces data, this data is consumed by T2, not by T3.
    This is because after T3 and T2 suspension, queue's waitobj chain is:

    waitobj->T2->T3

    Upon OS_Q_Put() call by T1, OS_ClearWaitObj() is called, T2 is found on waitobj head and made ready (OS_MakeTaskReady).
    T2 immediately takes the CPU, since its priority is higher than T1.
    T3 is made ready later, and does not find data in the queue, as it has been consumed by T2.

    OS_DeactivateP() should not always put the task in front of waitobj queue in my understanding. It would be better to perform an insertion sort based on priority value.


    Thanks in advance
    Best regards