Skip to content

Commit cf64823

Browse files
committed
more improvements
1 parent d49ef91 commit cf64823

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

docs/guides/blackboard_reference.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,39 @@ pointcloud instance by reference.
6363

6464
The 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

6969
To 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
7592
if(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

Comments
 (0)