Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better protect this->dataPtr->initialized with renderMutex. #1119

Merged
merged 2 commits into from
Oct 19, 2021

Conversation

mahiuchun
Copy link
Contributor

Tested with running ThreadSanitizer on some code involves camera sensor rendering.

@mahiuchun mahiuchun requested a review from iche033 as a code owner October 18, 2021 18:49
@github-actions github-actions bot added the 🔮 dome Ignition Dome label Oct 18, 2021
@codecov
Copy link

codecov bot commented Oct 19, 2021

Codecov Report

Merging #1119 (bf139a8) into ign-gazebo4 (6e85c08) will increase coverage by 0.00%.
The diff coverage is 60.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##           ign-gazebo4    #1119   +/-   ##
============================================
  Coverage        67.00%   67.00%           
============================================
  Files              244      244           
  Lines            18262    18263    +1     
============================================
+ Hits             12236    12237    +1     
  Misses            6026     6026           
Impacted Files Coverage Δ
src/systems/sensors/Sensors.cc 74.87% <60.00%> (+0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6e85c08...bf139a8. Read the comment docs.

@chapulina chapulina merged commit 6362bae into gazebosim:ign-gazebo4 Oct 19, 2021
WilliamLewww pushed a commit to WilliamLewww/ign-gazebo that referenced this pull request Dec 7, 2021
@@ -417,6 +417,7 @@ void Sensors::Update(const UpdateInfo &_info,
EntityComponentManager &_ecm)
{
IGN_PROFILE("Sensors::Update");
std::unique_lock<std::mutex> lock(this->dataPtr->renderMutex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is merged, but I just noticed this. If I understand correctly, having this mutex lock here could prevent sensors from updating in parallel with physics. This would happen if the Sensors system comes before the Physics system in the SDFormat file. Here's the sequence of events that could happen:

  1. In the Sensors::PostUpdate, a new render is triggered that takes a long time to complete. The render thread locks renderMutex and starts the render.
  2. In the next phase, Sensors::Update tries to acquire renderMutex and blocks because the render is not complete. This also blocks Physics::Update from being called because it comes after Sensors::Update.

Can some one verify this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔮 dome Ignition Dome
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants