【问题标题】:boost::shared_ptr references?boost::shared_ptr 引用?
【发布时间】:2012-10-26 11:46:06
【问题描述】:

我需要类似的东西:

boost::shared_ptr<A>  _class(...);

//Start async operation
boost::aiso::post(_class);

_class.relase();

while(_class)     // not working
{
   LOG("Wait for aync operation to complete");
}

【问题讨论】:

  • 您不能以这种方式等待 async.operation 完成。你的post 是什么?它会发布到另一个线程吗?
  • @IgorR。是正确的。您的问题意味着您实际上想要一个同步等待(这很容易实现)。这就是你想要的吗?
  • 是的,但我希望条件与 shared_ptr ref_cnt 相关。同时我用信号量实现了这个并解决了这个问题。

标签: boost synchronization boost-asio shared-ptr


【解决方案1】:

是的,它是安全的,因为post 复制了它的参数(我猜你的意思是io_service_.post())。 请参阅文档here

但是在你调用_class.release()之后,!!_class将永远是false,所以while(_class)永远不会执行循环体。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 2011-03-04
    • 1970-01-01
    • 2016-09-26
    • 2017-01-03
    • 1970-01-01
    相关资源
    最近更新 更多