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

Synchronization between renderer and handlers doesn't work #2004

Closed
wants to merge 3 commits into from

Conversation

v-ein
Copy link
Contributor

@v-ein v-ein commented Jan 6, 2023


name: Pull Request
about: Create a pull request to help us improve
title: Synchronization between renderer and handlers doesn't work
assignees: @hoffstadt


Description:
This fix replaces mvContext::mutex with a recursive_mutex and removes the manualMutexControl variable since it's not needed for a recursive mutex. This allows the handlers thread to properly lock the mutex while making changes to the widgets tree.

It also adds synchronization to some other code paths where I bumped into a crash or just noticed potential issues.

Concerning Areas:
There might be other areas that still need proper synchronization. I'm especially unsure about different messages in mvHandleMsg(). This should probably be researched in a separate issue and a separate PR, since the current PR does address the main concern of #1985 that manualMutexControl actually prevented mutex locking.

Another concern is that I didn't try to fix Linux and Mac implementations of mvViewport - I don't have a test system for that.

@hoffstadt
Copy link
Owner

A few small breaking changes were added on our part, once these are corrected, I can merge this finally!

@@ -2125,7 +2127,7 @@ split_frame(PyObject* self, PyObject* args, PyObject* kwargs)
&delay))
return GetPyNone();

if (!GContext->manualMutexControl) std::lock_guard<std::mutex> lk(GContext->mutex);
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just found a problem with this fix: it breaks split_frame(). Since it now properly locks the mutex, there's very little chance that waitOneFrame goes back from true to false. To fix that, it's sufficient to remove the line 2130 (locking the mutex) altogether: split_frame doesn't need the mutex.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, while split_frame can be fixed by removing the mutex lock in it, it could also be made more efficient using a condition variable instead of an atomic bool. This way it returns as soon as rendering of the new frame has ended, instead of polling the variable every 32 ms (and potentially waiting up to 32 ms longer than needed).

I've implemented this in my local copy and can share as a separate PR.

Copy link
Owner

Choose a reason for hiding this comment

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

You can submit with this PR if you'd like.

hoffstadt added a commit that referenced this pull request Mar 22, 2023
@hoffstadt
Copy link
Owner

Manually copied your code over. Let me know what email to use so I can co-author yet in the commit!

@hoffstadt hoffstadt closed this Mar 22, 2023
hoffstadt added a commit that referenced this pull request Mar 22, 2023
@v-ein
Copy link
Contributor Author

v-ein commented Mar 24, 2023

Thanks Jonathan! I've had a busy week or two and completely missed these comments...

Let me know what email to use so I can co-author yet in the commit!

You can use vein-github at outlook dot com.

}
else
{
GContext->viewport->clientHeight = cheight + 39;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't this break #1130 ? Not sure where these lines came from, I didn't have them in the original fix...

Copy link
Owner

Choose a reason for hiding this comment

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

Ooh. I believe so. Let me check (this was several fixes in a single commit).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have you had a chance to look at this? Any plans on how to handle it? Since this PR is closed and seems to have been included into 1.9, we probably need to open another PR to change the lines back, right?

I'm asking because I've started updating to 1.9 and would like to have a clean base upon which to cherry-pick my commits...

@v-ein v-ein deleted the bugfix/1985-sync-issues branch June 23, 2023 07:44
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