ct_self

The ct_self function returns an identifier for the currently running thread.

Prototype:

Ct_handle ct_self( void );

Parameters:

None.

Return Value:

A Ct_handle referring to the current thread.

Discussion:

The ct_self function returns a small struct, called a Ct_handle, whose contents uniquely identify the currently running thread. The application should treat this struct as a unit without trying to access the innards.

A Ct_handle serves as an address by which a thread may send a message to another thread. Calling ct_self() enables a thread to send a message to itself. More importantly, it enables a thread to send a message containing its own handle as a return address, so that the other thread can respond.

If called from a user exit, ct_self() returns a handle for the thread with which the user exit is associated.

Restrictions:

It is sensible to call ct_self() only from a thread or user exit, i.e. while the scheduler is running.

If you insist on calling ct_self() while the scheduler is not running, it will return a null handle -- a Ct_handle not pointing to any thread. If you use a null handle as the destination of a message, Cheap Threads will silently discard the message.


Home