//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();
}
如果a类在测试文件中,不在dll文件中,没问题,使用线程没问题, 当类在dll文件中,而out函数使用静态时,大多数时候它锁定,有时它通过。这是什么问题?