Use CfixCreateThread2 whenever you need to create a thread from within a test case and intend to call cfix APIs (i.e. CFIX_ASSERT etc) on this thread. CfixCreateThread2 is a wrapper for CreateThread/_beginthreadex with the added functionality that the thread is registered so that cfix can properly relate any assertions etc. raised on this thread to the current test case.
|For kernel mode tests, use CfixCreateSystemThread rather than CfixCreateThread2.|
CFIXAPI HANDLE CFIXCALLTYPE CfixCreateThread2( __in_opt PSECURITY_ATTRIBUTES ThreadAttributes, __in SIZE_T StackSize, __in PTHREAD_START_ROUTINE StartAddress, __in_opt PVOID Parameter, __in DWORD CreationFlags, __out_opt PDWORD ThreadId, __in ULONG Flags );
[in] Flags: If set to 0, CreateThread is called internally to create the thread. If set to CFIX_THREAD_FLAG_CRT, _beginthreadex is called instead so that the CRT will be fully initialized before StartAddress is called.
See MSDN for a discussion of remaining parameters.
If you spawn up a new thread using CfixCreateThread or CfixCreateThread2, this thread should terminate before the current test case ends -- otherwise, any further assertions generated by such a thread cannot be properly associated with the test case any more. As of cfix 1.5, this behavior is automatically enforced: After a test case ends, cfix will check the status of all child threads and, if necessary, will wait for their termination before continuing execution.