ct_clear
The ct_clear function cleans up the data structures internal to
Cheap Threads, reinitializing them for possible further use.
Prototype:
void ct_clear( void );
Parameters:
None.
Return Value:
None.
Discussion:
The ct_clear() function destroys all threads, calling any cleanup
functions that have been installed for them. Then it sets a series
of internal variables to their initial state.
Note that ct_clear() does not restore the default error
reporting function.
There are two circumstances when ct_clear() may be useful:
-
The application successfully creates one or more threads by
calling ct_create_thread(), but then
encounters an error condition before calling
ct_schedule(). By calling ct_clear(),
the application can destroy the threads already created, thereby
releasing the memory and possibly other resources associated with
the threads.
-
An error condition has put the Cheap Threads scheduler into an error
state in which it refuses to do anything useful. After calling
ct_clear() to clear the error state, the application can create one
or more threads and call ct_schedule() again.
Otherwise, calling ct_clear() is neither necessary nor useful. In
particular there is normally no need to call it before or after calling
ct_schedule(). In the absence of an error condition, the scheduler
performs the equivalent of ct_clear() before returning control to
the application.
Restrictions:
The ct_clear() function has no effect if called from a thread or user
exit. In other words it should be called only when the scheduler is
not running.
Home