File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -68,19 +68,21 @@ then there is no guarantee that a copy of the object being shared isn't accessed
68
68
69
69
To prevent this issue, we provide a different API that includes a locking mechanism.
70
70
71
- ``` cpp
72
- // ----- NOT thread-safe -------
73
71
72
+ This is ** NOT** thread-safe:
73
+
74
+ ``` cpp
74
75
std::shared_ptr<Pointcloud> cloud_ptr;
75
76
getInput ("cloud", cloud_ptr);
76
77
// modify the pointcloud referenced by cloud_ptr here
78
+ ```
77
79
78
- // ----- thread-safe alternative -------
80
+ The thread-safe alternative:
79
81
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"))
82
85
{
83
- // cast Any to std::shared_ptr<Pointcloud >
84
86
auto cloud_ptr = any_locked.get()->cast<std::shared_ptr<Pointcloud>>();
85
87
// modify the pointcloud referenced by cloud_ptr here
86
88
}
You can’t perform that action at this time.
0 commit comments