# Waiting for more than one MsgQs

**URL:** <https://forums.freertos.org/t/waiting-for-more-than-one-msgqs/3708>\
**Category:** Kernel\
**Created:** [September 25, 2007, 6:30am UTC](https://forums.freertos.org/t/waiting-for-more-than-one-msgqs/3708 "2007-09-25T06:30:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 25, 2007, 6:30am UTC](https://forums.freertos.org/t/waiting-for-more-than-one-msgqs/3708/1 "2007-09-25T06:30:25Z")

</div>

**[grumpy1234](https://sourceforge.net/u/grumpy1234/)** wrote on [Tuesday, September 25, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/a2f41f27/#9fca):

Hi everyone

I have some basic questions to freeRTOS:  
Is it possible to build a task which waits (blocks) for a semaphore (triggered by a timer interrupt or external HW interrupt) and a message queue at the same time and gets unblocked by either the semaphore or the message queue (whatever event happens first)?&nbsp; Or for several message queues? If that is not possible, which is the best way to implement it?

Cheers

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 25, 2007, 3:17pm UTC](https://forums.freertos.org/t/waiting-for-more-than-one-msgqs/3708/2 "2007-09-25T15:17:20Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 25, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/a2f41f27/#9fca/233d):

You can implement this by using one queue, then having the data that is posted to the queue contain a code as to what the data contains.&nbsp; For example:

typedef struct  
{  
\_\_\_\_unsigned portLONG ulCode;  
\_\_\_\_unsigned portLONG ulValue;  
} xData;

then

void vHandleEvents( void )  
{  
\_\_\_\_xQueueReceive( xQueue, &xData, portMAX\_DELAY );  
\_\_\_\_switch( xData.ulCode )  
\_\_\_\_{  
\_\_\_\_\_\_\_\_case SEMAPHORE\_DATA : /\* Processing as if it was the semaphore goes here. \*/  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_break;  
\_\_\_\_\_\_\_\_case QUEUE\_DATA&nbsp;&nbsp;&nbsp;&nbsp; : /\* Processing as if it was the queue goes here. \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ulReceivedValue = xData.ulValue;  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_break;  
\_\_\_\_}  
}

When you send data to the queue, you send an xData object with ulCode set to QUEUE\_DATA, and ulValue set to the value you want to post.&nbsp; Etc.

Regards.
