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
  • Hello Francesco,

    queues can have more than one producer but only one consumer.
    This means that more than one task is allowed to store new data in the queue but only one task is allowed to get data from the queue.

    Best regards,
    Til
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Francesco,

    this is only a limitation of queues, you can have more than one consumer with mailbox.

    Regards,
    Til
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.