mq_notify

Langue: en

Version: JULY 2003 (mandriva - 01/05/08)

Autres sections - même nom

Section: 2 (Appels système)

NAME

mq_notify - notify process that a message is available

SYNOPSIS

gcc [ flag... ] file ... -lmqueue -lpthread [ library... ]

#include <mqueue.h>

int mq_notify(mqd_t mqdes, const struct sigevent *notification);

DESCRIPTION

The mq_notify() function provides an asynchronous mechanism for processes to receive notice that messages are available in a message queue, rather than synchronously blocking (waiting) in mq_receive().

If notification is not NULL, this function registers the calling process to be notified of message arrival at an empty message queue associated with the message queue descriptor, mqdes. The notification specified by notification will be sent to the process when the message queue transitions from empty to non-empty. At any time, only one process may be registered for notification by a specific message queue. If the calling process or any other process has already registered for notification of message arrival at the specified message queue, subsequent attempts to register for that message queue will fail.

The notification argument points to a structure that defines the type of notification to be generated upon message arrival.

If notification->sigev_notify is SIGEV_SIGNAL, then the signal specified in notification->sigev_signo will be sent to the process.

If notification->sigev_notify is SIGEV_THREAD, then a new thread will be started with its starting routine defined by notification->sigev_notify_function. This routine as an argument will receive the notification->sigev_value value. The thread is created with notification->sigev_notify_attributes attributes. If notification->sigev_notify_attributes is NULL, then the thread is created as PTHREAD_CREATE_DETACHED and other attributes set to default.

If notification is NULL or notification->sigev_notify is SIGEV_NONE, and the process is currently registered for notification by the specified message queue, the existing registration is removed. The message queue is then available for future registration.

When the notification is sent to the registered process, its registration is removed. The message queue is then available for registration.

If a process has registered for notification of message arrival at a message queue and some processes is blocked in mq_receive() waiting to receive a message when a message arrives at the queue, the arriving message will be received by the appropriate mq_receive(), and no notification will be sent to the registered process. The resulting behavior is as if the message queue remains empty, and this notification will not be sent until the next arrival of a message at this queue.

Any notification registration is removed if the calling process either closes the message queue or exits.

RETURN VALUES

Upon successful completion, mq_notify() returns 0; otherwise, the function returns -1 and sets errno to indicate the error condition.

DIAGNOSTICS

The mq_notify() function will fail if:
EBADF
The mqdes argument is not a valid message queue descriptor.
EBUSY
A process is already registered for notification by the message queue.
EINVAL
Invalid signal number in notification->sigev_signo or notification->sigev_notify is not one of the SIGEV_NONE, SIGEV_SIGNAL, SIGEV_THREAD.
EFAULT
notification points outside your accessible address space.
ENFILE
notification type was SIGEV_THREAD and current process doesn't have any more free file descriptors. See NOTES below.

There are possible other error codes - see below.

NOTES

SIGEV_THREAD notification is implemented in the following way: when process first registers for SIGEV_THREAD notofication a new thread is created. This manager thread is responsible for actual creating of all other threads upon notification. This manager thread is left running even when there is no more regstered notifications.

The internal SIGEV_THREAD implementation need some file descriptors to do the work so mq_notify can fail when you have no much free (as a rule: no more than 5 is needed). Also note that when creating a new manager thread fails mq_notify() will return appropriate error.

AUTHORS

Krzysztof Benedyczak <golbi@mat.uni.torun.pl>
Michal Wronski <wrona@mat.uni.torun.pl>

CONFORMING TO

IEEE Std 1003.1-2001

SEE ALSO

mq_receive(2), mq_send(2)