后面的部分是我的程序,但它并不像我期望的那样工作。我想要主窗口程序在 dll 中调用函数“MyDllIniSys”,让 dll 渲染窗口每可能 32 微秒,直到主窗口程序设置“bIAutoRender”不等于 1。 所以我希望函数“MyDllIniSys”启动线程,并立即返回。 但是在我所做的事情中,程序无法运行,因为如果线程启动,它将永远不会返回。 我怎样才能得到它,有人请。帮助。 非常感谢
static void renderOneFrame(const boost::system::error_code& /*e*/,
boost::asio::deadline_timer* t, int* iNeedAutoRender)
{
//call Who use this DLL, let it refresh the window
if(OnRefreshEvent)
{
OnRefreshEvent();
}
if(*iNeedAutoRender == 1)
{
t->expires_at(t->expires_at() + boost::posix_time::microseconds(iIRenderMicroSenconds));
t->async_wait(boost::bind(renderOneFrame,
boost::asio::placeholders::error, t, iNeedAutoRender));
}
}
EXTERN_C MYDLLAPI INT MyDllIniSys(INT WindowWidth,INT WindowHeight)
{
COgreRenderLoader myLoader;
myLoader.IniOgre(externalWindowHandle,WindowWidth,WindowHeight);
boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::microseconds(iIRenderMicroSenconds));
t.async_wait(boost::bind(renderOneFrame,
boost::asio::placeholders::error, &t,&bIAutoRender));
boost::thread thread1(boost::bind(&boost::asio::io_service::run, &io));
//io.run();
thread1.join();
//thread1.start_thread();
return 1;
}
最佳答案
调用 thread1.join() 将阻塞,直到 thread1 完成执行。将其关闭,您的函数将启动线程并立即返回。
线程将继续,即使 thread1 对象超出范围,as you can see from this question .
关于c++ - 我如何在后台的 dll 中使用 muti boost 线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15939883/