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 的区别
基础教程推荐
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- c++ STL设置差异 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
