Does the asio io_service increase the guarantee of two concurrent call chains?
In my program using boost asio io_service I want to have two parallel call chains. Two endless loops write and read two USB ports. But does the asio io_service increase the guarantee of two concurrent call chains? Take a 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;
}
He prints
1 2 1 2 1 ...
as the current implementation of io_service is a fifo dispatcher. Is it guaranteed in the future, it won't print
1 1 1 1 1 ...
?
source to share
At this time, it io_service
does not make any guarantees as to the order in which the processors are contacted. Thus, it io_service
can choose to call only one call chain. Currently, only strand
warranties are indicated.
With that said, I wouldn't bother too much about that io_service
, which is currently out of warranty. Since Asio has become a standard networking library as it becomes a standard networking library , it can be assumed that the scheduling of the handler will be determined throughout the specification process. In particular, the use of the io_service
proposed executors and planners should provide specific guarantees regarding the scheduling behavior and its parameters.
source to share