ct_subscribe

The ct_subscribe function specifies that a specified thread should receive all distributed messages of a specified type.

Prototype:

int ct_subscribe( Ct_msgtype type, Ct_handle handle );

Parameters:

type
A non-zero integer designating the type of message. Zero is reserved to denote the absence of a message. Otherwise, the message types are defined by the application.

handle
Identifies the thread to be subscribed to the message type. This value must have been returned from ct_create_thread(), ct_create_sleeping_thread(), or ct_self(). Otherwise the results are undefined.

Return Value:

CT_OKAY if successful, or CT_ERROR if not.

Discussion:

The subscription mechanism enables a thread to send messages to other threads without specifically knowing their identities. This facility is particularly useful in an application that creates and destroys threads dynamically.

A thread may be subscribed to multiple message types, and a message may be distributed to multiple subscribed threads.

Typically the thread will be subscribed just after its creation, whether before the scheduler starts or, by another thread, while the scheduler is running. A thread may also subscribe itself.

Messaging is described in detail elsewhere.

See also: ct_unsubscribe(), ct_unsubscribe_all().

Restrictions:

The application may call ct_subscribe() before starting the scheduler or while it is running. Once the scheduler terminates, calling ct_subscribe() invokes undefined behavior.
Home