NXThreadExit

Terminates the calling thread.

Library:LibC
Classification:NKS
Service:Threads

Syntax

  #include <nks/thread.h>
   
  void NXThreadExit (
     void  *status);
  

Parameters

status

(IN) Points to an application-defined exit value for the thread.

Remarks

When an application thread calls NXThreadExit, it is terminated. If it was created as a joinable thread, its exit value is returned to the sibling thread that successfully performs the NXThreadJoin operation on this departing thread. If a daemon thread calls NXThreadExit, that thread is terminated.

The context hosted by an exiting application or daemon thread might not be automatically destroyed (see NXThreadCreate for details). If the context is not automatically destroyed, it is reset and is available for reuse by the application.

If NXThreadExit is called during the execution of a work context, the work execution terminates, and the work context is reset and is available for reuse. If the work context was scheduled as periodic work, the work context is not rescheduled.

When a detached thread exits, it cleans up after itself automatically. However, when a joinable thread exists and a thread is not already waiting to join the exiting thread, the system maintains sufficient state to support subsequent calls to NXThreadJoin. If you do not call NXThreadJoin on an exited joinable thread, system resources are held up unnecessarily.

When the virtual machine is terminated, all resources allocated to the virtual machine are freed. If the departing thread is the last application thread in the virtual machine, NXThreadExit terminates the containing virtual machine. When the thread executing main calls NXThreadExit, the virtual machine is not torn down unless this thread is also the last application thread.

NOTE:Daemon threads do not participate in the decision to terminate the virtual machine.

For sample code, see KeyValue.c.

See Also