@@ -63,20 +63,39 @@ pointcloud instance by reference.
6363
6464The most notable issue, when using the ` shared_ptr ` approach, is that it is ** NOT thread safe** .
6565
66- IF multithreading is used, inside a Node (remember that BT.CPP is single-threaded by default),
67- then there is no guarantee that a copy of the object being shared isn't accessed during writing .
66+ If a custom asynchronous Node has its own thread, then the actual object might be accessed by other
67+ threads at the same time .
6868
6969To prevent this issue, we provide a different API that includes a locking mechanism.
7070
71+ First, when creating our ports we can use a plain ` Pointcloud ` , no need to wrap it inside a ` std::shared_ptr ` :
7172
7273``` cpp
73- // inside this scope (as long as any_locked exists), a mutex protecting
74- // the instance of "cloud" remains locked
74+ PortsList AcquirePointCloud::providedPorts ()
75+ {
76+ return { OutputPort<Pointcloud>("cloud") };
77+ }
78+
79+ PortsList SegmentObject::providedPorts ()
80+ {
81+ return { InputPort<std::string>("obj_name"),
82+ InputPort<Pointcloud>("cloud"),
83+ OutputPort<Pose3D>("obj_pose") };
84+ }
85+ ```
86+
87+ To access the instance of Pointcloud by pointer/reference:
88+
89+ ``` cpp
90+ // inside the scope below, as long as "any_locked" exists, a mutex protecting
91+ // the instance of "cloud" will remain locked
7592if (auto any_locked = getLockedPortContent(" cloud" ))
7693{
7794 if(any_locked->empty())
7895 {
7996 // the entry in the blackboard hasn't been initialized yet.
97+ // You can initialize it doing:
98+ any_locked.assign(my_initial_pointcloud);
8099 }
81100 else if(Pointcloud* cloud_ptr = any_locked->castPtr<Pointcloud >())
82101 {
0 commit comments