Queue set - reseting

yevpator75 wrote on Tuesday, May 28, 2019:


I have 2 queues and a task that is designed as a state machine.
In some states I need to pend only on one queue among the two I mentioend above and in one specific state - on both of the queues. For this specific case I created a queue set. Thus, we have:

  1. Two separates quees
  2. The queue set that consits of 2 the same queues

The problem I’m facing is that whenever I receive a message on on of the queues in some states, this triggers the queue set too and when I move to the task state where I pend on the queue set I immediately wakeup because the queue was set by posting to one of its queues. Then, after my queue set wakes up I need to receive a message from this queue and the queue is empty causing configASSERT to fail.

My question is about a way to overcome the problem I expalined above? THat is to say, if I receive a message on the queue while blocking on it, reset the QueueSet so it wont hurt another queue ?

I do have a couple of ideas :

  1. Not to use the Queue set, but to create a separate task for the 2nd queue
  2. When I wakeup on the queue set and then I check which is the activated member, to ignore the message if the activated member is empty

Hope my description is clear enough.

Thanks for any advice !

rtel wrote on Thursday, May 30, 2019:

Hope my description is clear enough.

Afraid not :o) The only way to use a queue set is to always read from
the queue set first, then always read from the queue the set tells you
contains data - otherwise the state of the queue and the state of the
set become inconsistent.

You could do something like every time you write to a queue you follow
up by writing to a something like a counting semaphore - then have the
receiving tasks block on the counting semaphore if they need to block,
then peek each queue to see which contains data when they unblock.