Message Queue Overview

This topic describes the message queue overview.

A message queue is a mechanism for passing data:

  • between threads within a process

  • between threads that run in separate processes.

The mechanism provides a way to send data (messages) to an interested party without needing to know whether anyone is listening nor needing to know the identity of a recipient.

A message is an object, usually an instance of a class, that is placed into a queue for delivery to recipients. A queue is normally created to deal with messages of a given type. This means that a queue is created to deal with messages of a defined (fixed) length. The size of a queue, i.e. the maximum number of messages, or slots, it can contain is defined and fixed when the queue is created. The size of message for which a queue is created, and the size of the queue is arbitrary, being limited only by system resources.

A single queue can be shared by many readers and writers. Several threads may be reading from and writing to the same message queue, but only one thread can access the queue at a time. If multiple clients attempt to read from the message queue a panic will be raised.

A message queue is represented by a DMsgQueue kernel side object, to which the reader and the writer can open a handle, a RMsgQueue object. A message queue is a reference counted object, being derived from CObject, which means that it is not persistent; it is deleted when the last handle to it is closed. The queue itself is simply a block of memory divided into slots, managed by the DMsgQueue object.

Handle to a message queue

A message queue is created, opened, written to and read from through a message queue handle, an RMsgQueue object. This is a templated class, where the template parameter defines the message type.

RMsgQueue is derived from RMsgQueueBase, which together form a thin template class/base class pair. RMsgQueueBase provides the implementation, while RMsgQueue provides type safety. An RMsgQueueBase object is a valid message queue handle, but does not offer the type safety that RMsgQueue does.

Message queues are used for one-way, one to one communications only. The message queue is therefore unicast. If there are multiple readers of the message queue only one will receive the message.

Visibility of a message queue

A message queue can be:

  • named and be visible to all processes - a global queue

  • local to the current process, i.e. not visible to any other process - a local queue