查看函数签名CreateThread
几乎与相同_beginthreadex
。
_beginthread
,_beginthreadx
vsCreateThread
HANDLE WINAPI CreateThread(
__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in SIZE_T dwStackSize,
__in LPTHREAD_START_ROUTINE lpStartAddress,
__in_opt LPVOID lpParameter,
__in DWORD dwCreationFlags,
__out_opt LPDWORD lpThreadId
);
uintptr_t _beginthread(
void( *start_address )( void * ),
unsigned stack_size,
void *arglist
);
uintptr_t _beginthreadex(
void *security,
unsigned stack_size,
unsigned ( *start_address )( void * ),
void *arglist,
unsigned initflag,
unsigned *thrdaddr
);
此处的备注说_beginthread
可以使用__cdecl
或__clrcall
调用约定作为起点,也_beginthreadex
可以将__stdcall
或__clrcall
用作起点。
我认为人们对内存泄漏的任何评论CreateThread
都已经有十多年的历史了,应该忽略不计。
有趣的是,这两个_beginthread*
功能实际上都是在我的机器内部调用CreateThread
的C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src
。
// From ~line 180 of beginthreadex.c
/*
* Create the new thread using the parameters supplied by the caller.
*/
if ( (thdl = (uintptr_t)
CreateThread( (LPSECURITY_ATTRIBUTES)security,
stacksize,
_threadstartex,
(LPVOID)ptd,
createflag,
(LPDWORD)thrdaddr))
== (uintptr_t)0 )
{
err = GetLastError();
goto error_return;
}