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

Fix race condition and improve performance of rmw_wait #203

Closed
wants to merge 3 commits into from

Conversation

Yadunund
Copy link
Member

No description provided.

clalancette and others added 2 commits May 24, 2024 14:08
With the current code in rmw_wait, there is a race between
the time when we check whether we should wait, and whether
an event comes in.  If we've determined we should wait,
and an event comes in (and does cv.notify()) *before* we
start waiting, then we won't wake up until the timeout.

This commit fixes that by taking a mutex across *all* of
rmw_wait().  This means that if an event comes in while
we are holding the mutex, it will actually cause us to
never go to sleep.  This fixes the race.

While we are in here, we notice that we can improve performance
by just having a single lock in the context that everything
uses.  This allows us to skip the entire attach/detach dance,
getting rid of one of the 3 loops in rmw_wait.

Signed-off-by: Chris Lalancette <[email protected]>
@Yadunund Yadunund mentioned this pull request Jun 20, 2024
@clalancette
Copy link
Collaborator

It turns out that this way of doing things is not really feasible, given the design of rmw_wait. In particular, because this is a per-context condition_variable, it can spuriously wake us up for things that we are not interested in. That would require us to do a check to see if we should go back to sleep, waiting on something we do care about.

Because of that, I'm going to close out this PR. #205 is the start of a series of PRs that should fix this in a different way.

@Yadunund Yadunund deleted the clalancette/rmw-wait-again branch June 26, 2024 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants