msgQSend and msgQReceive Question - VxWorks
This is a discussion on msgQSend and msgQReceive Question - VxWorks ; A question regarding msgQLib in vxworks. Typically msgQ's are used for
send msg between 2 tasks. However, if I do a msgQSend on a msgQ ID and
subsequently do a msgQReceive from the same msgQ ID from the SAME TASK
...
-
msgQSend and msgQReceive Question
A question regarding msgQLib in vxworks. Typically msgQ's are used for
send msg between 2 tasks. However, if I do a msgQSend on a msgQ ID and
subsequently do a msgQReceive from the same msgQ ID from the SAME TASK
will this work and dequeue the msg that I queued using msgQSend
previously. For example will something like this work and/or have any
side effects?
taskA()
{
msgQSend(some_buffer);
msgQReceive(another_buffer);
}
My question is when msgQReceive is called will I get the msg sent
previously using msgQSend on some_buffer. Thanks in advance for your
answers.
-
Re: msgQSend and msgQReceive Question
On Jun 11, 9:03 am, wamba.ku...@gmail.com wrote:
> A question regarding msgQLib in vxworks. Typically msgQ's are used for
> send msg between 2 tasks. However, if I do a msgQSend on a msgQ ID and
> subsequently do a msgQReceive from the same msgQ ID from the SAME TASK
> will this work and dequeue the msg that I queued using msgQSend
> previously. For example will something like this work and/or have any
> side effects?
>
> taskA()
> {
> msgQSend(some_buffer);
> msgQReceive(another_buffer);
>
> }
>
> My question is when msgQReceive is called will I get the msg sent
> previously using msgQSend on some_buffer. Thanks in advance for your
> answers.
The example given in the manual is instructive ( vxworks application
programmers guide )
/* In this example, task t1 creates the message queue and sends a
message
* to task t2. Task t2 receives the message from the queue and simply
* displays the message.
*/
/* includes */
#include
#include
/* defines */
#define MAX_MSGS (10)
#define MAX_MSG_LEN (100)
MSG_Q_ID myMsgQId;
task2 (void)
{
char msgBuf[MAX_MSG_LEN];
/* get message from queue; if necessary wait until msg is available
*/
if (msgQReceive(myMsgQId, msgBuf, MAX_MSG_LEN, WAIT_FOREVER) ==
ERROR)
return (ERROR);
/* display message */
printf ("Message from task 1:\n%s\n", msgBuf);
}
#define MESSAGE "Greetings from Task 1"
task1 (void)
{
/* create message queue */
if ((myMsgQId = msgQCreate (MAX_MSGS, MAX_MSG_LEN, MSG_Q_PRIORITY))
== NULL)
return (ERROR);
/* send a normal priority message, blocking if queue is full */
if (msgQSend (myMsgQId, MESSAGE, sizeof (MESSAGE), WAIT_FOREVER,
MSG_PRI_NORMAL) == ERROR)
return (ERROR);
}
In the code above the msgQSend is in two tasks but there does not seem
to be a reason that
you could not put it in a single task. However be aware that both
calls block the current task
when the queue is full for the sender or empty for the receiver so if
you are seeing problems
with putting the code in a single task that may be the cause.
--
Brad Phelan
http://xtargets.com
-
Re: msgQSend and msgQReceive Question
On Jun 11, 3:15 pm, bradphelan wrote:
> On Jun 11, 9:03 am, wamba.ku...@gmail.com wrote:
>
>
>
> > A question regarding msgQLib in vxworks. Typically msgQ's are used for
> > send msg between 2 tasks. However, if I do a msgQSend on a msgQ ID and
> > subsequently do a msgQReceive from the same msgQ ID from the SAME TASK
> > will this work and dequeue the msg that I queued using msgQSend
> > previously. For example will something like this work and/or have any
> > side effects?
>
> > taskA()
> > {
> > msgQSend(some_buffer);
> > msgQReceive(another_buffer);
>
> > }
>
> > My question is when msgQReceive is called will I get the msg sent
> > previously using msgQSend on some_buffer. Thanks in advance for your
> > answers.
>
> The example given in the manual is instructive ( vxworks application
> programmers guide )
>
> /* In this example, task t1 creates the message queue and sends a
> message
> * to task t2. Task t2 receives the message from the queue and simply
> * displays the message.
> */
> /* includes */
> #include
> #include
> /* defines */
> #define MAX_MSGS (10)
> #define MAX_MSG_LEN (100)
> MSG_Q_ID myMsgQId;
> task2 (void)
> {
> char msgBuf[MAX_MSG_LEN];
> /* get message from queue; if necessary wait until msg is available
> */
> if (msgQReceive(myMsgQId, msgBuf, MAX_MSG_LEN, WAIT_FOREVER) ==
> ERROR)
> return (ERROR);
> /* display message */
> printf ("Message from task 1:\n%s\n", msgBuf);}
>
> #define MESSAGE "Greetings from Task 1"
> task1 (void)
> {
> /* create message queue */
> if ((myMsgQId = msgQCreate (MAX_MSGS, MAX_MSG_LEN, MSG_Q_PRIORITY))
> == NULL)
> return (ERROR);
> /* send a normal priority message, blocking if queue is full */
> if (msgQSend (myMsgQId, MESSAGE, sizeof (MESSAGE), WAIT_FOREVER,
> MSG_PRI_NORMAL) == ERROR)
> return (ERROR);
>
> }
>
> In the code above the msgQSend is in two tasks but there does not seem
> to be a reason that
> you could not put it in a single task. However be aware that both
> calls block the current task
> when the queue is full for the sender or empty for the receiver so if
> you are seeing problems
> with putting the code in a single task that may be the cause.
>
> --
> Brad Phelanhttp://xtargets.com
There shouldn't be any issues to send and receive over a single msgQ
and single task. It would be overhead to send and receive on the
message queue for single task, rather it can be accessed as a simple
pointer.
Ranga