Difference between Afxbeginthread and CreateThread(Afxbeginthread 和 CreateThread 的区别)
问题描述
使用 Afxbeginthread 有什么缺点吗?我们什么时候应该使用 AfxBeginThread,什么时候应该使用 CreateThread API.
Is there any drawbacks for using Afxbeginthread. When should we use AfxBeginThread and when should we use CreateThread API.
推荐答案
对于 MFC 程序,使用 AfxBeginThread.
For MFC programs, use AfxBeginThread.
CreateThread 是原始的 Win32.它与部分标准库不兼容.
CreateThread is raw Win32. It's incompatible with parts of the standard library.
_beginthread 是 C 标准库的一部分.它添加了额外的代码来处理标准库的其他部分的线程安全,如果您使用 CreateThread 代替,这些部分将是不安全的.
_beginthread is part of the C standard library. It adds extra code to handle thread safety for other parts of the standard library that would be unsafe if you used CreateThread instead.
AfxBeginThread (显然)是 MFC 的一部分.除了 _beginthread 支持的线程安全之外,它还增加了一些(如果只有少数)C++ 细节.
AfxBeginThread is (obviously enough) part of MFC. Along with the thread safety supported by _beginthread, it adds some (if only a few) C++ niceties.
所以,如果你的程序的其余部分也是纯的、原始的 Win32,不使用标准库或 MFC,你应该只使用 CreateThread.如果您使用的是 MFC,通常应该使用 AfxBeginThread 而不是 CreateThread.
So, you should only use CreateThread if the rest of your program is also pure, raw Win32, with no use of the standard library or MFC. If you're using MFC otherwise, you should normally use AfxBeginThread rather than CreateThread.
这篇关于Afxbeginthread 和 CreateThread 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Afxbeginthread 和 CreateThread 的区别
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
