Destroys an execution context.
#include <nks/thread.h>
int NXContextFree (
NXContext_t ctx);
(IN) Points to the context to destroy.
If successful, returns 0; otherwise, returns a nonzero error code:
The execution context to be destroyed must be idle because it is illegal to call NXContextFree on a context that is currently being hosted by a thread. The context structure to be destroyed must have been allocated by calling NXContextAlloc.
Each context can support a fixed number of key/value pairs that can be used to host application-defined per-context data areas. When a context is destroyed, all active key/value pairs are cleaned up.
Work contexts are created by calling NXContextAlloc with NX_CTX_WORK and have to be managed and freed by an application. Normal contexts are created by calling NXContextAlloc with NX_CTX_NORMAL and are usually destroyed automatically when the hosting thread terminates. However, an application can manage normal contexts explicitly (see NXThreadCreate).
The application must determine when it is safe to call NXContextFree on a previously allocated context. It must ensure that no thread is currently hosting the context and that no thread would attempt to host the thread before calling NXContextFree.
You can also call NXThreadJoin to manage contexts with applications when you are using joinable application threads. Once NXThreadJoin returns, the context hosted by the application thread that was joined is safe to be freed or reused (assuming that other application threads do not attempt to host this context).
You don't have to rely on NXThreadJoin for context management; you can use any scheme you prefer to determine when it is safe to free or reuse a context.
When a context is freed, the associated destructor is called for only the key-associated data for all set keys (see NXKeyDelete).
For sample code, see ThrDestr.c.