Skip to content

Commit 9804b91

Browse files
committed
changes
1 parent e8ee8f3 commit 9804b91

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/guides/blackboard_reference.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,21 @@ then there is no guarantee that a copy of the object being shared isn't accessed
6868

6969
To prevent this issue, we provide a different API that includes a locking mechanism.
7070

71-
```cpp
72-
// ----- NOT thread-safe -------
7371

72+
This is **NOT** thread-safe:
73+
74+
```cpp
7475
std::shared_ptr<Pointcloud> cloud_ptr;
7576
getInput("cloud", cloud_ptr);
7677
// modify the pointcloud referenced by cloud_ptr here
78+
```
7779
78-
// ----- thread-safe alternative -------
80+
The thread-safe alternative:
7981
80-
// inside this scope, the object in the blackboard is protected by a mutex
81-
if(auto any_locked = getLockedPortContent("cloud")
82+
```cpp
83+
// inside this scope, the mutex protecting the instance of "pointcloud" remains locked
84+
if(auto any_locked = getLockedPortContent("cloud"))
8285
{
83-
// cast Any to std::shared_ptr<Pointcloud>
8486
auto cloud_ptr = any_locked.get()->cast<std::shared_ptr<Pointcloud>>();
8587
// modify the pointcloud referenced by cloud_ptr here
8688
}

0 commit comments

Comments
 (0)