Main Thread

From cxwiki

The main thread is the primary entry point of any Process. This is the thread on which the main() function is called.
 
Amongst all threads in the process, it is special in a number of ways:
  • All subsiduary threads must exit before the main thread exits, or undefined behaviour results.
  • The native user interface controls may only be created and accessed on the main thread.
  • Certain other platform APIs may only be accessed on the main thread.
  • CXThread::GetCurrentThread() returns nullptr for the main thread (but it also does this for other externally-created threads).
  • CXThread::IsCurrentThreadMainThread() returns true for the main thread only.
  • The native user interface may stop responding if the main thread becomes blocked. Typically this means that the main thread should ONLY service the native user interface and other very short-running tasks, with the bulk of application logic running on preemptive CXThreads or possibly cooperative CXFibers.