Skip to content

Conversation

@AviaAv
Copy link
Contributor

@AviaAv AviaAv commented Aug 20, 2025

Tracked on: [LRS-1331]

@AviaAv AviaAv requested a review from Nir-Az August 20, 2025 10:51
@Nir-Az Nir-Az requested review from OhadMeir and Copilot and removed request for Nir-Az August 21, 2025 13:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a thread join operation before reassigning the check_for_device_updates_thread to prevent potential resource leaks and undefined behavior.

  • Adds a joinability check and join operation before thread reassignment
  • Ensures proper cleanup of existing thread before creating a new one

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

std::weak_ptr< notifications_model > notification_model_protected( viewer.not_model );
const context & ctx( viewer.ctx );
if (check_for_device_updates_thread.joinable())
check_for_device_updates_thread.join();
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

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

Consider adding a detach() call as an alternative to join() to avoid blocking the current thread. If the existing thread is performing a long-running operation, join() will block until completion, which could cause UI freezing or performance issues.

Suggested change
check_for_device_updates_thread.join();
check_for_device_updates_thread.detach();

Copilot uses AI. Check for mistakes.
_updates_profile );
std::weak_ptr< notifications_model > notification_model_protected( viewer.not_model );
const context & ctx( viewer.ctx );
if (check_for_device_updates_thread.joinable())
Copy link
Collaborator

Choose a reason for hiding this comment

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

It was a detached thread before as i see

Copy link
Contributor

Choose a reason for hiding this comment

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

It was a detached thread before and that was the problem previous PR solved - a thread trying to access object that don't exist anymore (device disconnected)

Copy link
Collaborator

Choose a reason for hiding this comment

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

weak_ptr?

const context & ctx( viewer.ctx );
if (check_for_device_updates_thread.joinable())
check_for_device_updates_thread.join();
check_for_device_updates_thread = std::thread( [ctx,
Copy link
Contributor

Choose a reason for hiding this comment

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

If calling this while thread is joinable, that the task we want to perform (checking for updates) is already being performed. Do we need to create another thread and check again? Can't we use previous thread outcome?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We also need to see how the UI is affected, it may get it to stuck, that's why it was detached.
If access is a problem we can try using weak_ptr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do that, but it's not related to the thread being joinable - once we create a thread and not detach it, we need to join it, even if it finishes running, so being joinable doesn't indicate that it's still running

Copy link
Collaborator

Choose a reason for hiding this comment

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

We had no issue with check for updates before the last PR (this code was there for 5 years ), we did had an issue with the platform camera new thread no?
Am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Platform camera was another issue. This thread handling was changed because of a problem when a camera was connected and quickly disconnected.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe all use cases were solved in the past when adding a weak ptr,
@AviaAv can you revert the previous PR locally and say which resource is not longer protected maybe we can handle it?
I even prefer to skip the request than to delay the UI if this is the solution we go with

@Nir-Az Nir-Az changed the title add join before thread reassignment Fix Check For Updates crash Aug 27, 2025
@Nir-Az Nir-Az merged commit 09b64d2 into realsenseai:development Aug 27, 2025
26 checks passed
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.

3 participants