线程内部详细信息
1.CreateThread与_beginthreadex的区别: CreateThread是系统API,_beginthreadex是CRT (运行时库)函数. _beginthreadex
_endthreadex释放_beginthreadex分配给tid数据结构的内存。
如果在线程函数中调用了CRT函数(注意:并非所有CRT函数都是其中的一部分),则线程函数必须由_beginthreadex而不是CreateThread函数创建。 否则会导致内存泄漏。
如果要在非主课程线程上执行以下操作,则必须使用多线程版本的C runtime library,并使用_beginthreadex和_endthreadex :
)1)使用malloc ()和free ) )或new和delete
)2)使用在stdio.h或io.h中声明的函数
(3)浮点变量或浮点运算函数的使用
)4)调用使用静态缓冲区的任何runtime函数,例如:asctime (,strtok )、rand )
2._beginthreadex与_beginthread的区别
在_beginthreadex内部自动调用_endthreadex。
在_beginthread内部自动调用_endthread。
_endThread内部自动调用CloseHandle以关闭当前thread内核对象的句柄,因此使用_beginthread时,在主线程上调用CloseHandle以关闭子线程的句柄_endthreadex比_endthread安全。 当前Thread内核对象的句柄不会自动关闭。 因此,如果使用_beginthreadex,则必须使用CloseHandle关闭子线程的句柄。
参考: http://www.cn blogs.com/lgx qf/archive/2009/02/10.html