C++ c++;当类销毁它时使用异步锁定,使用线程没有问题 //在dll文件中 #包括 甲级 { 公众: () { //:m_thread=std::thread([this]{}); m_f=std::async(std::launch::async,[this]{}); } ~a() { m_f.get();//大多数时候有m_f锁,有时没有 //m_thread.join();//如果使用thread没有问题 } 私人: 标准:未来的m_f; //标准:螺纹m_螺纹; }; //输出到dll 无效aa() { 静态a aa; } //在测试文件中 #包括“a.h” #pragma注释(lib,“a.lib”) int main() { aa(); }
如果类a在测试文件中,而不是在dll文件中,则无问题,使用线程无问题,C++ c++;当类销毁它时使用异步锁定,使用线程没有问题 //在dll文件中 #包括 甲级 { 公众: () { //:m_thread=std::thread([this]{}); m_f=std::async(std::launch::async,[this]{}); } ~a() { m_f.get();//大多数时候有m_f锁,有时没有 //m_thread.join();//如果使用thread没有问题 } 私人: 标准:未来的m_f; //标准:螺纹m_螺纹; }; //输出到dll 无效aa() { 静态a aa; } //在测试文件中 #包括“a.h” #pragma注释(lib,“a.lib”) int main() { aa(); },c++,asynchronous,dll,future,C++,Asynchronous,Dll,Future,如果类a在测试文件中,而不是在dll文件中,则无问题,使用线程无问题, 当类位于dll文件中,而out函数使用静态时,大多数时候它是锁定的,有时它是传递的。有什么问题吗?您可能需要重新表述它,以便它包含一个。还有,当它锁上的时候,它到底锁在哪里?将它附加到调试器并停止它以检查线程的状态并获取回溯。 //in dll file #include <future> class a { public: a() { //:m_thread=std::thre
当类位于dll文件中,而out函数使用静态时,大多数时候它是锁定的,有时它是传递的。有什么问题吗?您可能需要重新表述它,以便它包含一个。还有,当它锁上的时候,它到底锁在哪里?将它附加到调试器并停止它以检查线程的状态并获取回溯。
//in dll file
#include <future>
class a
{
public:
a()
{
//:m_thread=std::thread([this]{});
m_f = std::async(std::launch::async,[this]{});
}
~a()
{
m_f.get(); //most time there m_f lock,sometime not
//m_thread.join(); // if use thread no problem
}
private:
std::future<void> m_f;
//std::thread m_thread;
};
//out to dll
void aa()
{
static a aa;
}
//in test file
#include "a.h"
#pragma comment(lib,"a.lib")
int main()
{
aa();
}