【发布时间】:2012-11-20 18:32:15
【问题描述】:
我有一些代码在 boost 线程中运行,它修改了由主线程处理的东西,这些东西不起作用,这是有道理的。
在 android 上,我将拥有 Handler,它是一个消息队列,它将在主线程上执行我的代码,我可以将任何我想要的参数传递给这个处理程序。
我想对 boost 做同样的事情
所以在我的主线程上,我执行以下操作:
boost::thread workerThread(boost::bind(&SomeClass::pollService, this));
我的 pollService 方法:
SomeClass::pollService()
{
//get some stuff from a web service
//parse the json response
//NEEDED part: call a function to be executed on the main thread and hand it some functions
}
附:我看过很多 io_service.post 的例子,但我仍然不知道该怎么做,而且我读了一个回答说要使用 asio strand 但我也无法理解。
有人可以帮我把它笨一点吗? 请不要写太抽象的东西,我不会理解,我没有这方面的经验。 谢谢
【问题讨论】:
标签: boost boost-asio boost-thread boost-bind