并推动两个并行调用链的ASIO io_service对象执行保证? [英] Does boost asio io_service guarantee execution of two parallel call chains?

查看:161
本文介绍了并推动两个并行调用链的ASIO io_service对象执行保证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序,使用boost ASIO io_service对象,我想有两个并行的调用链。两个无限循环写入和读出两个USB端口。但提振两个并行调用链的ASIO io_service对象执行保证?看看这个小例子:

In my program, using boost asio io_service, I want to have two parallel call chains. Two endless loops writing and reading to two usb ports. But does boost asio io_service guarantee execution of two parallel call chains? Look at this minimal example:

#include <boost/asio/io_service.hpp>
#include <functional>

class Chain
{
public:
    Chain(boost::asio::io_service &io_service, const std::string &message)
        : io_service(io_service)
        , message(message)
    {}

    void call()
    {
        std::cout << message << std::endl;
        io_service.post(std::bind(&Chain::call, this));
    }

private:
    boost::asio::io_service &io_service;
    std::string message;
};

int main()
{
    boost::asio::io_service io_service;

    Chain chain1(io_service, "1");
    Chain chain2(io_service, "2");

    chain1.call();
    chain2.call();

    io_service.run();

    return 0;
}

它打印

1
2
1
2
1
...

由于当前io_service对象实现FIFO调度。它是在未来保证的广告也不会打印

because current io_service implementation is fifo dispatcher. Is it guarenteed in the future it will not prints

1
1
1
1
1
...

推荐答案

io_service对象目前不作任何处理程序的调用顺序的保证。因此, io_service对象可以选择只调用一个调用链。目前,只有 指定的担保。

The io_service currently makes no guarantees about the invocation order of handlers. Thus, the io_service could choose to invoke only a single call chain. Currently, only a strand specifies guarantees.

随着中说,我不会太担心了 io_service对象目前还没有作出保证。由于短耳是轨道上成为标准的网络库一可以想象,处理调度将在整个规范过程来定义。特别是提出了执行者和调度的 io_service对象的使用应提供具体的保证,而调度行为和它的选项。

With that said, I would not worry too much about the io_service currently not making the guarantee. As Asio is on track of becoming the standard networking library, one can imagine that handler scheduling will be defined throughout the specification process. In particular, the io_service's usage of the proposed executors and schedulers should provide specific guarantees as to the scheduling behavior and its options.

这篇关于并推动两个并行调用链的ASIO io_service对象执行保证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆