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 in updater thread. #26

Merged
merged 3 commits into from
Feb 5, 2025

Conversation

dkosmari
Copy link

@dkosmari dkosmari commented Feb 5, 2025

This fixes a race condition, where the updater thread was reading sCheckUpdateThread (and assuming it wasn't null) while it was being assigned in the parent thread. The intended usage for std::jthread is for the thread function to receive a std::stop_token as the first argument, eliminating the need to reach into the std::jthread object.

This also changes sCheckUpdateThread to std::optional, avoiding one extra heap allocation, costing only 8 bytes.

There are also some minor cleanup changes I did while I was bored looking for the bug.

Daniel K. O. (dkosmari) added 2 commits February 5, 2025 04:47
… argument to the

thread.

This also avoids allocating the updater thread object on the heap, by using
`std::optional` instead of `std::unique_ptr`.

Code simplified: `std::jthread` destructor will stop and join the thread automatically.
Copy link
Contributor

@Maschell Maschell left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, one small question though

@Maschell Maschell merged commit 3a1db7e into wiiu-env:0.1.7-dev Feb 5, 2025
2 checks passed
@dkosmari dkosmari deleted the fix-race-condition-in-updater branch February 5, 2025 22:33
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