[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


C.6 Restrictions for Win32 API Routines

It is strongly recommended that the Win32 API routine TerminateThread() not be used. This routine terminates a thread immediately, but does not provide a means for the thread to clean up any context it may have acquired while executing. Context that is left in an inconsistent state when calling TerminateThread(), such as a locked mutex, can cause unpredictable results. The only time that this routine should be used is if the entire process is being terminated one thread at a time. Terminating just one thread in an application with this routine, and allowing the process to continue, is not recommended.

The Win32 API routine ExitThread() should not be called by a thread created using any of the DECthreads creation routines (for example, pthread_create()). ExitThread() bypasses normal cleanup handlers and internal management routines. ExitThread() also leaves internal data structures in an inconsistent state and may produce unpredictable results.