QueueReceive and QueueSet strange behavior

Hello,

I observe strange behavior but I first let me describe the situation with some pseudo code :slight_smile:

QueueHandle_t q1;
QueueHandle_t q2;
QueueSetHandle_t set;

void foo()
{
       xQueueSend(task2_queue, 0);
       //do something
       xQueueReceive(q2, 1000 ticks);     // wait for response from task2
       // Here is THE PLACE were magic happens :)
}

void task1(void *param)
{
      q1 = xQueueCreate(SIZE, sizeof(some_struct));
      q2 = xQueueCreate(SIZE, sizeof(some_struct));
      set = xQueueCreateSet(2 * SIZE);
      xQueueAddToSet(set, q1);
      xQueueAddToSet(set, q2);

      QueueHandle_t queue;

      while(1) {
             queue = (QueueHandle_t) xQueueSelectFromSet(set, 50);
             if (queue == q2)  {
                   // do something
             }
             foo();

      }
}

When I wait for queue q2 in function foo() the execution time of xQueueReceive is always 1000 ticks despite the fact that that the message arrived earlier.

The strange thing is when I remove q2 from QueueSet receive in foo() execute immediate after something is in queue.

I did some measurements with the test code and when q2 is added to QueueSet execution of xQueueReceive in foo() is always 1000 ticks, but when q2 is not added to QueueSet is execution of xQueueReceive is 200 ticks.

I have no idea what is going on :).
Any help is welcome :slight_smile:

Thanks.

Is task2_queue a completely different queue not mentioned anywhere else, and so not really relevant to the set?

Exactly, task2_queue is no relevant to the set. task2_queue is used to receive message from task1. q2 is used to receive response from task2.

One issue is that once you put a queue into a queue set, you MUST follow the procedure of first ask the queue set for what queue (if any) has a message. Your foo directly reads from the q2 queue and messes up the sequencing.

Thanks. Apparently I skipped this part somehow:

"A receive (in the case of a queue) or take (in the case of a semaphore) operation must not be performed on a member of a queue set unless a call to xQueueSelectFromSet() has first returned a handle to that set member. "