为什么建议使用_beginthread和_beginthreadex以及_beginthread和_beginthreadex差异点
2012-12-03 15:58
351 查看
1,为什么建议使用_beginthread和_beginthreadex:
A thread in an executable that calls the C run-time library (CRT)should use the
_beginthread and _endthread functions for threadmanagement rather than
CreateThread and ExitThread; this requiresthe use of the multi-threaded version of the CRT. It is safe to call
CreateThreadand ExitThread from a thread in a DLL that links to the static CRT aslong as the thread does not call the
DisableThreadLibraryCalls function.
也就是说:CreateThread创建的线程,使用的不是多线程版本CRT;而_beginthread使用的是多线程版本。
2,_beginthread和_beginthreadex差异点
A thread in an executable that calls the C run-time library (CRT)should use the
_beginthread and _endthread functions for threadmanagement rather than
CreateThread and ExitThread; this requiresthe use of the multi-threaded version of the CRT. It is safe to call
CreateThreadand ExitThread from a thread in a DLL that links to the static CRT aslong as the thread does not call the
DisableThreadLibraryCalls function.
也就是说:CreateThread创建的线程,使用的不是多线程版本CRT;而_beginthread使用的是多线程版本。
2,_beginthread和_beginthreadex差异点
| _beginthread | _beginthreadex |
原型 | 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 ); |
start_address | The routine at start_address must use the __cdecl calling convention and should have no return value | The routine at start_address must use the __stdcall calling convention and must return a thread exit code. |
return value | If successful, each of these functions returns a handle to the newly created thread | |
_beginthread returns 1L on an error, in which case errno is set to EAGAIN if there are too many threads or to EINVAL if the argument is invalid or the stack size is incorrect. | _beginthreadex returns 0 on an error, in which case errno and _doserrno are set. | |
if the newly created thread exits too quickly | the handle returned to the caller of _beginthread might be invalid or, worse, point to another thread | the handle returned by _beginthreadex has to be closed by the caller of _beginthreadex, so it is guaranteed to be a valid handle if _beginthreadex did not return an error. |
terminate a thread | You can call _endthread or _endthreadex explicitly to terminate a thread; however, _endthread or _endthreadex is called automatically when the thread returns from the routine passed as a parameter. | |
_endthread automatically closes the thread handle | _endthreadex does not closes the thread handle | |
ohter diffrence | with _beginthreadex, you can use security information, set the initial state of the thread (running or suspended), and get the thread identifier of the newly created thread. You are also able to use the thread handle returned by _beginthreadex with the synchronization APIs, which you cannot do with _beginthread. |
相关文章推荐
- beginthread和beginthreadex的使用方法
- beginthread和beginthreadex的使用方法
- 为什么不使用 CreateThread, 而使用_beginthreadex
- beginthread和beginthreadex的使用方法
- 使用 ConTest 进行多线程单元测试 - 为什么并行测试很困难以及如何使用 ConTest 辅助测试
- 使用CreateThread函数和_beginThreadex函数的注意事项
- Maven是什么,以及为什么要使用Maven
- epoll的水平触发和边缘触发,以及边缘触发为什么要使用非阻塞IO
- web前端优化时为什么不建议使用css @import
- VC++ MSDN中的 _beginthreadex与_endthreadex 的使用例子
- 实例浅析epoll的水平触发和边缘触发,以及边缘触发为什么要使用非阻塞IO
- Effective Java Item7:Avoid Finalizers,解释为什么finalize是不安全的,不建议使用
- unresolved external symbol __beginthreadex错误的解决——谈谈在Win32 Consle Application如何使用MFC类
- 将BootstrapJS和AngularJS结合使用以及为什么不用jQuery
- _beginthreadex 和 _beginthread 的区别
- Zepto和Jquery的区别,以及在做移动端开发时,我们为什么选择使用zepto
- 为什么建议php字符串使用单引号而不是双引号
- _beginthreadex CreateThread _beginthread
- 为什么某些电感下面建议不要铺铜(以及layout相关事项)?
- ExtJs4组件中initComponent方法介绍以及为什么要使用this.callParent();