Boost绑定AIX xlc io_service运行

时间:2013-02-21 10:25:56

标签: boost-asio aix boost-bind xlc

我试图使用boost编译项目,将asio :: io_service绑定到boost :: thread,我得到错误,我不知道如何解决 使用:IBM XL C / C ++ for AIX,V11.1(5724-X13),版本:11.01.0000.0006(AIX 7.1)

    "/home/clag/projects/tomas/include/boost/asio/detail/posix_fd_set_adapter.hpp", line 33.30: 1540-0198 (W) The omitted keyword "private" is assumed for base class "noncopyable".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.46: 1540-0219 (S) The call to "boost::bind" has no best match.
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.58: 1540-1229 (I) Argument number 1 is an rvalue of type "overloaded function: boost::asio::io_service::run".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.100: 1540-1229 (I) Argument number 2 is an rvalue of type "const boost::reference_wrapper<const boost::asio::io_service>".
    "/home/clag/projects/tomas/include/boost/bind/bind_mf_cc.hpp", line 30.5: 1540-1202 (I) No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::reference_wrapper<const boost::asio::io_service> >(unsigned long (io_service::*)() const, reference_wrapper<const boost::asio::io_service>)".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.58: 1540-1231 (I) The conversion from argument number 1 to "unsigned long (boost::asio::io_service::*)() const" uses the resolved overloaded function "size_t boost::asio::io_service::run()".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.100: 1540-1231 (I) The conversion from argument number 2 to "boost::reference_wrapper<const boost::asio::io_service>" uses "the identity conversion".
    "/home/clag/projects/tomas/include/boost/bind/bind_mf_cc.hpp", line 20.5: 1540-1202 (I) No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::reference_wrapper<const boost::asio::io_service> >(unsigned long (io_service::*)(), reference_wrapper<const boost::asio::io_service>)".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.58: 1540-1231 (I) The conversion from argument number 1 to "unsigned long (boost::asio::io_service::*)()" uses the resolved overloaded function "size_t boost::asio::io_service::run()".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.100: 1540-1231 (I) The conversion from argument number 2 to "boost::reference_wrapper<const boost::asio::io_service>" uses "the identity conversion".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.35: 1540-0219 (S) The call to "boost::bind" has no best match.
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.47: 1540-1229 (I) Argument number 1 is an rvalue of type "overloaded function: boost::asio::io_service::run".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.98: 1540-1229 (I) Argument number 2 is an rvalue of type "boost::asio::io_service *".
    "/home/clag/projects/tomas/include/boost/bind/bind_mf_cc.hpp", line 30.5: 1540-1202 (I) No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::asio::io_service *>(unsigned long (io_service::*)() const, io_service *)".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.47: 1540-1231 (I) The conversion from argument number 1 to "unsigned long (boost::asio::io_service::*)() const" uses the resolved overloaded function "size_t boost::asio::io_service::run()".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.98: 1540-1231 (I) The conversion from argument number 2 to "boost::asio::io_service *" uses "the identity conversion".
    "/home/clag/projects/tomas/include/boost/bind/bind_mf_cc.hpp", line 20.5: 1540-1202 (I) No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::asio::io_service *>(unsigned long (io_service::*)(), io_service *)".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.47: 1540-1231 (I) The conversion from argument number 1 to "unsigned long (boost::asio::io_service::*)()" uses the resolved overloaded function "size_t boost::asio::io_service::run()".
    "/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.98: 1540-1231 (I) The conversion from argument number 2 to "boost::asio::io_service *" uses "the identity conversion".
    "/home/clag/projects/tomas/include/boost/asio/impl/write.hpp", line 276.7: 1540-0198 (W) The omitted keyword "private" is assumed for base class "detail::base_from_completion_cond<CompletionCondition>".
    "/home/clag/projects/tomas/include/boost/asio/impl/write.hpp", line 276.7: 1540-0198 (W) The omitted keyword "private" is assumed for base class "detail::base_from_completion_cond>boost::asio::detail::transfer_all_t>"

导致错误的代码:

    acceptor_thread_.reset(new boost::thread(boost::bind(&boost::asio::io_service::run, boost::cref(*accept_io_service_))));
    for (int i = 0; i < agent_config_.threads(); i++) {
        thread_group_.create_thread(boost::bind(&boost::asio::io_service::run, work_io_service_.get()));
    }

说明:

    boost::shared_ptr<boost::asio::io_service> accept_io_service_;
    boost::shared_ptr<boost::thread> acceptor_thread_;
    boost::shared_ptr<boost::asio::io_service> work_io_service_;
    boost::thread_group thread_group_;

请注意,这可能只是一些标志选项,但我无法在任何地方找到它 因为相同的代码在Linux(GCC),HP-UX(aCC)和Windows(MSVC)上编译得非常好。

寻求帮助

4 个答案:

答案 0 :(得分:2)

快速谷歌搜索表明AIX存在重载解析问题,尤其是涉及模板时。因此,可能值得尝试不同的方法来减少需要发生的过载分辨率。

例如,可以使用boost::mem_fn()代替boost::bind()

std::size_t (io_service::*run)() = &io_service::run;
boost::thread t(boost::mem_fn(run), io_service);

此外,如果编译器仍然在解决重载问题,那么考虑编写一个简单的仿函数。 boost::thread()构造函数的唯一要求是func参数是可复制的,func()必须是有效的表达式。

struct service_runner
{
  explicit service_runner(boost::shared_ptr<boost::asio::io_service> io_service)
    : io_service(io_service)
  {}
  std::size_t operator()() { return io_service->run(); }
  boost::shared_ptr<boost::asio::io_service> io_service;
};

...

boost::thread t((service_runner(io_service)));

需要考虑的其他要点:

  • 首选编译符合规范的代码,而不是使用编译器标志来允许编译不合格的代码。在这种特殊情况下,io_service::run()是非const成员函数,但绑定到它的accept_io_service实例参数通过boost::cref()作为常量引用传递。需要添加编译器标志,例如gcc的-fpermissive,以允许编译不合格的代码。使用这些选项要非常小心,因为它们可能会掩盖严重的问题。
  • 考虑将boost::shared_ptr作为实例句柄传递给绑定调用。只要线程仍在运行,这将使io_service保持活动状态。否则,当线程仍处理其事件循环时,可以删除io_service,从而很有可能调用未定义的行为。

答案 1 :(得分:1)

好奇的是,您是否正在使用您正在使用的编译器的IBM boost库补丁? http://www-01.ibm.com/support/docview.wss?uid=swg27006911

答案 2 :(得分:0)

查看4个可能尝试的候选人的消息,差异似乎与const相关

No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::reference_wrapper<const boost::asio::io_service> >(unsigned long (io_service::*)() const, reference_wrapper<const boost::asio::io_service
>)".
No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::reference_wrapper<const boost::asio::io_service> >(unsigned long (io_service::*)(), reference_wrapper<const boost::asio::io_service>)".
No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::asio::io_service *>(unsigned long (io_service::*)() const, io_service *)".
No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::asio::io_service *>(unsigned long (io_service::*)(), io_service *)".

由于您使用的是V11.1编译器,因此默认情况下有一些修复程序未启用,您可以尝试使用以下选项

-qxflag = EnableIssue214PartialOrdering 这将启用与C ++核心语言问题214

相关的几个修复程序

-qxflag = FunctionCVTmplArgDeduction2011 这使得一些C ++ 2011澄清了参数推论

这些更改是V12.1编译器的默认设置,但不适用于V11.1编译器

答案 3 :(得分:0)

如果有人偶然发现这个问题,我会添加额外的反应。 因为我发现这与编译器无法解析使用哪个函数有关,如果函数具有相同的名称,但参数不同。

示例:

void test(int a);
void test(int a, int b);

无法使用,并会导致与上述类似的错误 但改变这样的名字:

void test(int a);
void test2(int a, int b);

...将完美无缺。

这绝对是比创建包装器更少的开销解决方案(正如我自己在做观察之前所做的那样)。

希望有人能发现这个有用。