c++ - MFC 多线程 : AfxBeginThread vs Boost. 线程?

标签 c++ multithreading mfc boost-thread

我有一个 MFC 应用程序,我想在其中加入多线程。最初我正在考虑使用 Boost.Thread,因为使用 boost 开发通常很容易。但是,我想知道是否存在任何问题,我是否应该使用 AfxBeginThread 在 MFC 上下文中确保安全?

最佳答案

我找到了这篇 Microsoft 文章:Multithreading: Programming Tips .它说:

Accessing MFC Objects from Non-MFC Threads

If you have a multithreaded application that creates a thread in a way other than using a CWinThread object, you cannot access other MFC objects from that thread. In other words, if you want to access any MFC object from a secondary thread, you must create that thread with one of the methods described in Multithreading: Creating User-Interface Threads or Multithreading: Creating Worker Threads. These methods are the only ones that allow the class library to initialize the internal variables necessary to handle multithreaded applications.

我打算在模型 View 演示器上下文中使用线程,以便对一些长时间运行的演示器任务进行多线程处理。由于演示者需要与 View 进行通信,我认为这很可能符合访问 MFC 对象的条件(至少是间接访问)。基于此,我决定暂时使用 AfxBeginThread 线程创建方法。

关于c++ - MFC 多线程 : AfxBeginThread vs Boost. 线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7826175/

相关文章:

multithreading - 写入 BufferedWriter 的最佳 Scala 线程安全方式是什么?

java - 使用哨兵停止线程不起作用

c++ - 在更新期间 boost 锁定变量 vector

layout - CWinAppEx CleanState - 重置布局

c++ - 如何在文件打开对话框中隐藏特定控件? (使用 CFileDialog 创建的对话框)

c++ - 在 CListCtrl 中为图像添加状态图标

c++ - 在从 std::vector 移动的对象上调用 .clear()、.shrink_to_fit()、.empty() 是否合法?

c++ - 如何使用 OpenCV 计算图像的结构张量

c++ - fprintf stdout 没有 100% 准确地转储数据

c++ - 如何在 C++ 中格式化日期和时间字符串