To assist in cleaning up state information for a thread, callers can provide a routine pointed to by the process_done argument.
The following code fragment shows the required syntax for a process_done() routine.
void process_done(void *ctx2,
void *ctx1);
|
The following table lists the arguments required for a process_done routine, and gives a description of each.
|
Required Arguments |
Description |
|---|---|
|
ctx2 |
The value of the last pointer stored by process_message in the ctx2 call argument for this thread. |
|
ctx1 |
The caller-supplied private context passed as ctx1 to mtaDequeueStart(). |
The following code fragment demonstrates the type of actions taken by a process_done routine.
void process_done(ctx2, ctx1)
{
struct our_state_t *state = (our_state_t *)ctx2;
if (!state)
return;
/*
* Take steps to undo the state
* (for example, close any sockets or files)
*/
...
/*
* Free the memory allocated by process_message()
* to store the state
*/
free(state)
}
|