ct_valid_handle
The ct_valid_handle function determines whether a Ct_handle refers
to a valid thread.
Prototype:
int ct_valid_handle( const Ct_handle * pH );
Parameters:
- pH
-
Pointer to a Ct_handle obtained previously from a call to
ct_create_thread(),
ct_create_sleeping_thread(),
or ct_self().
Return Value:
CT_TRUE if the pH parameter points to the handle of a valid thread;
otherwise CT_FALSE.
Discussion:
A Ct_handle is always valid when it is first returned successfully
from ct_create_thread(), ct_create_sleeping_thread(), or ct_self().
However, it becomes invalid when the associated thread terminates.
The ct_valid_handle() function enables a thread to determine whether
another thread is still alive.
If the pointer parameter is not NULL but does not point to a value
previously obtained from ct_create_thread(),
ct_create_sleeping_thread(), or ct_self(), then the results are
undefined. In order to respond correctly to such a wild pointer, Cheap
Threads would have to maintain and consult a list of previously created
threads. This approach, while possible, would create more complexity
and overhead than it is likely to be worth.
When the Cheap Threads scheduler terminates, all Ct_handles become
not only invalid but also meaningless. If a pointer to such a defunct
Ct_handle is passed to ct_valid_handle, the results are undefined,
even during a subsequent call to
ct_schedule().
Restrictions:
The ct_valid_handle() function is intended to be called from a thread
or user exit, i.e. while the scheduler is running. It is possible,
but not very useful, to call it between creating one or more threads
and calling ct_schedule(). Calling it at any other times invokes
undefined behavior, unless you pass it a NULL pointer.
Home