vijayanand1231
vijayanand1231

Reputation: 447

RTOS : Is it possible to have two Message Queue's for a Single Task?

I have created a task A and two message Queues Q1, Q2. Is it possible for the task A to wait on two message Queue?

As i know it is not possible, since in case of blocking message Q calls, the task will block itself(blocked state) when it is not having any message to process.

For eg., If Q1 has msgs and Q2 has no msgs, then in case of Q1, task will be in ready state and incase of Q2, task has to be in blocked state.

A task cannot be in 2 states at a time.

Is my understanding is correct?

Upvotes: 0

Views: 2020

Answers (3)

Clifford
Clifford

Reputation: 93556

The precise method would depend on your RTOS, but essentially you need to wait on an event or semaphore, and then poll the queues (non-blocking/zero timeout read). The sending tasks must place the message in the appropriate queue, then set the event or semaphore - this should be done in a single task interface function - the sending tasks should not have to know the mechanics of the receiving tasks communications.

If you use an event flag, you can use a separate flag for each queue, so you know which queue to read from (one or the other or both), but because event flags are not counting objects, you would need to poll the queue iteratively until it is exhausted in case there is more than message on the queue.

A counting semaphore is of some use, but only tells you the total number of messages, not which queue(s) they are on, so you would have to check both of them each time the semaphore is taken. This might lead to two messages being read for one semaphore count (one from each queue), followed by a sem-take with no corresponding message. You could augment the semaphore with shared data or your RTOS may be able to report the number of messages in a queue.

A binary semaphore would work like the event flag, except there would be no way of telling which queue has a message, so you would have to poll both.

Upvotes: 2

Onur Turhan
Onur Turhan

Reputation: 1257

Most of the RTOS do not provide this feature, but you can implement.

As an example RTOS; GHS-INTEGRITY has this feature built-in, that can you wait on one or more; message queue receive event, timer expired event, device rx buffer get event, device tx buffer sent event at the same line(time).

Upvotes: 0

Jeff Lamb
Jeff Lamb

Reputation: 5865

I think it depends on the implementation of the RTOS. You could certainly write an RTOS that has the ability to make a call to pend on two queues. It's just a RTOS call with two arguments. Then the RTOS manages those two queues and knows that the task is pending on both of them. However, I've never seen an RTOS that implements this.

Upvotes: 0

Related Questions