使用std::shared_ptr线程化构建块

Threading Building Blocks using std::shared_ptr

本文关键字:构建 线程 std shared 使用 ptr      更新时间:2023-10-16

我刚开始和TBB合作。不得不说它看起来很好,但我遇到了以下问题。在std::shared_ptr中使用lambda似乎不起作用。

source_node<int>(g,[&](int& val) -> bool {val = 0; return true;},false);
source_node<std::shared_ptr<int>(g,[&](std::shared_ptr<int> val) -> bool {val = std::make_shared<int>(0);return true;},false);

有以下编译错误:

error: C2665: 'std::shared_ptr<int>::shared_ptr' : none of the 5 overloads could convert all the argument types
C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDEmemory(504): could be 'std::shared_ptr<int>::shared_ptr<main::<lambda_484cee4d4b0231890bebaeba94e0ddad>,bool>(std::nullptr_t,_Dx,_Alloc)'
with
[
    _Dx=main::<lambda_484cee4d4b0231890bebaeba94e0ddad>
]

基本上int已经被std::shared_ptr取代了。

任何想法都将受到赞赏!

问候奥

谢谢Mike Seymour

source_node<std::shared_ptr<int>>(g,[&](std::shared_ptr<int> val) -> bool {val = std::make_shared<int>(0);return true;},false);