我有一份asio::io_service::strand. 复制的链及其源是不同的执行者吗?换句话说,传递给复制链的函数和传递给源链的另一个函数是否有可能由两个不同的线程同时执行?
或者这两个分支在逻辑上都是“一个分支”,这意味着传递给它们中的任何一个的工作都不会与传递给它们的其他工作一起执行?
查看示例
asio::io_service ioService;
asio::io_service::strand strandFromIoService{ioService};
asio::io_service::strand strandFromStrand{strandFromIoService};
strandFromIoService.post(boost::bind(&firstFunction));
strandFromStrand.post(boost::bind(&secondFunction));
// then use a pool of threads to service io_service ...
// can firstFunction and secondFunction be executed in one time?
Run Code Online (Sandbox Code Playgroud) 我想知道std::forward这里是否有感觉。
template <class T>
void juju(T && x) {
std::forward<T>(x).jaja();
}
Run Code Online (Sandbox Code Playgroud)
我想它没有任何意义,因为它this始终是方法调用中的指针,因此如果它是由右值或左值引用组成的,则没有区别。但请确认我的直觉或解释我为什么错了。
上面的示例是此代码的简化方法,包含jujubeing for_each、TbeingExecutionPolicy和jajabeing get_devices。