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

common: add ParameterUpdater for thread-safe parameter updates #34186

Closed
wants to merge 7 commits into from

Conversation

deanlee
Copy link
Contributor

@deanlee deanlee commented Dec 8, 2024

The GIL does not protect against race conditions when accessing attributes like self.is_metric across multiple threads. This PR introduces the ParameterUpdater class, which periodically updates parameters in a separate thread and ensures safe access through a mutex.
It also resolves a potential race condition in selfdrived by ensuring that parameters like self.CP.openpilotLongitudinalControl are accessed only in the main thread.

it's currently used in selfdrived and card, and can be extended to other modules requiring updated parameters.

@deanlee deanlee force-pushed the card_add_ParamsUpdater branch 3 times, most recently from 963b0b2 to 4a6a539 Compare December 8, 2024 18:40
@deanlee deanlee changed the title card: improve thread-safety with ParameterUpdater class selfdrive: improve thread-safety with ParameterUpdater class Dec 8, 2024
@deanlee deanlee changed the title selfdrive: improve thread-safety with ParameterUpdater class selfdrive: add ParameterUpdater for thread-safe parameter updates Dec 8, 2024
@deanlee deanlee force-pushed the card_add_ParamsUpdater branch 3 times, most recently from 8dc6df5 to ff659a1 Compare December 8, 2024 20:05
@deanlee deanlee changed the title selfdrive: add ParameterUpdater for thread-safe parameter updates common: add ParameterUpdater for thread-safe parameter updates Dec 8, 2024
@deanlee deanlee force-pushed the card_add_ParamsUpdater branch 5 times, most recently from 5a29cd6 to 76b212f Compare December 12, 2024 18:22
@deanlee deanlee marked this pull request as ready for review December 12, 2024 18:29
@deanlee deanlee force-pushed the card_add_ParamsUpdater branch from 76b212f to d7400d5 Compare December 12, 2024 19:26
@deanlee deanlee closed this Dec 19, 2024
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.

1 participant