Mailboxes
Thread Scheduling 4-67
Example 4-15. MBX Example With Two Types of Tasks
/*
* ======== mbxtest.c ========
* Use a MBX mailbox to send messages from multiple writer()
* tasks to a single reader() task.
* The mailbox, reader task, and 3 writer tasks are created
* statically.
*
* This example is similar to semtest.c. The major differences
* are:
* - MBX is used in place of QUE and SEM.
* - the ‘elem’ field is removed from MsgObj.
* - reader() task is *not* higher priority than writer task.
* - reader() looks at return value of MBX_pend() for timeout
*/
#include <std.h>
#include <log.h>
#include <mbx.h>
#include <tsk.h>
#define NUMMSGS 3 /* number of messages */
#define TIMEOUT 10
typedef struct MsgObj {
Int id; /* writer task id */
Char val; /* message value */
} MsgObj, *Msg;
/* Mailbox created with Config Tool */
extern MBX_Obj mbx;
/* "trace" Log created with Config Tool */
extern LOG_Obj trace;
Void reader(Void);
Void writer(Int id);
/*
* ======== main ========
*/
Void main()
{
/* Does nothing */
}