ct_install_pre_function

The ct_install_pre_function function installs a user exit that the scheduler will invoke immediately before running each thread's own callback function.

Prototype:

Ct_user_exit ct_install_pre_function( Ct_user_exit func );

Parameters:

func
A pointer to a callback function taking a void * as a parameter and returning an int. The function should return either CT_OKAY to indicate success or CT_ERROR to indicate failure.

Return Value:

A pointer to the previous pre-thread user exit function.

Discussion:

For convenience, the ct.h header declares a typedef Ct_user_exit for the pointer type received and returned by this function.

Immediately before invoking each thread's own callback function, the scheduler invokes the pre-thread user exit, if one is installed, passing it the same void pointer that it will pass to the thread's own callback function.

A pre-thread user exit executes fully in the context of the thread following it. For example, if the user exit calls ct_self(), it receives the same return value that the following thread would receive. It can terminate that thread by calling ct_exit() -- the thread will still run, but for only one last time. Because it receives the same void pointer as the thread's own callback function, it can access the same data.

If the application saves the return value of ct_install_pre_function(), it can restore the previous user exit.

The application can disable whatever pre-thread user exit is in effect by passing a null pointer to ct_install_pre_function().

See also: ct_install_post_function()

Restrictions:

The application may call ct_install_pre_function() at any time, although it is pointless for it to do so once the scheduler has terminated.
Home