我如何在后台的dll中使用多boost线程
how can I use muti boost thread in a dll in background
后部分是我的程序,但它不像我期望的那样工作。我希望主窗口程序在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对象超出了作用域,从这个问题中可以看出
相关文章:
- BOOST线程:线程还是进程
- 如何解决传递给boost线程的函数中的歧义
- cpp 为什么 boost::线程内部的循环不遍历所有值并且推送相同的值?
- C 从类的构造函数运行Boost线程
- 重新分配独立的boost ::线程安全吗?
- Boost::线程如何在主线程和工作线程之间同步
- 链接Boost线程库
- BOOST ::线程内会成员功能调用返回unique_lock Instantiation错误
- Boost ::线程何时终止?如何管理Boost ::线程
- 链接到boost ::线程失败
- 在C 中处理Boost线程条件
- Poco任务管理器/Boost线程混合和匹配
- 创建一个 boost::线程 带有 boost::bind() 或不带
- 为不受支持的平台调整Boost线程/进程
- 删除boost ::线程后代
- 我需要在Boost线程功能中调用Unlock()
- C OPENCV图像在Boost线程中不显示
- boost ::线程在删除可加入线程时存在什么问题
- 增强异步插座和Boost ::线程
- 如何使boost ::线程入睡