# OS_ReceiveMessage

## Syntax

      #include <nitro/os.h>

      BOOL OS_ReceiveMessage(
           OSMessageQueue*   mq,
           OSMessage*        msg,
           s32               flag );

## Arguments

mq | Pointer to the message queue
msg | Received message
flag | When `OS_MESSAGE_BLOCK` is set, the `OS_ReceiveMessage` function blocks empty queues. When `OS_MESSAGE_NOBLOCK` is set, the `OS_ReceiveMessage` function immediately returns whether or not the queue is empty.

## Return Values

Returns `TRUE` if the message was removed without any problems. If `OS_MESSAGE_NOBLOCK` was specified and the queue was empty, FALSE is returned.

## Description

Removes a message from the message queue Also puts all threads waiting to send a message to this queue into executable state. The sending threads are executed in order of priority.

If `OS_MESSAGE_BLOCK` is set up in `flag`, the thread that called this function will be paused if the queue is empty. The thread resumes immediately when message(s) are sent to the queue. If there are other receiving threads with higher priority, those are executed first, so be aware of the fact that they may remove the messages. If the message queue is empty when this thread comes to be executed, it will suspend again until another message is sent to the queue.

If `OS_MESSAGE_NOBLOCK` is set up in `flag`, the process immediately returns to the thread that was called. If the queue is not empty, `TRUE` is returned. If it is empty, `FALSE` is returned.

## See Also

`OS_InitMessageQueue, OS_SendMessage, OS_JamMessage, OS_ReadMessage
`

## Revision History

2004/03/12 Added `OS_ReadMessage` to See Also.
2003/12/01 Initial version.

CONFIDENTIAL