gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:07:28 26 4
gpt4 key购买 nike

我有一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com