-
Notifications
You must be signed in to change notification settings - Fork 50
Update block tip in the gui thread #177
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
Conversation
Does the handler need to have disconnect() called when the NodeModel cleans up possibly? I'm having a hard time seeing which object in the lambda execution would be invalid and cause the segfault. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code change looks acceptable to me. The reasoning for which is nicely explained in this Stackoverflow answer:
... The reason to use
QMetaObject::invokeMethod
if the recipient object might be in another thread is that attempting to call a slot directly on an object in another thread can lead to corruption or worse if it accesses or modifies non-thread-safe data.
However, I am curious about the seg fault error you mentioned in the description. Would you please add some points on what exactly you think caused the error?
I agree that this change is acceptable. It's ok to do simple setters on the gui thread. My guess is that doing so forces the juicy part of the lambda to only execute while the NodeModel object is still alive but there is also the NodeImpl that adds its own wrapper to the lambda so it could be that object's lifetime as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK eca5252, I have reviewed the code and it looks OK, I agree it can be merged.
@johnny9 I don't understand this, can you rephrase it? |
gui-qml/src/node/interfaces.cpp Line 373 in 3984614
|
The segfault comes from not calling The alternative to having some mutex is not ideal because we don't want to block the GUI and vice-versa So the approach is to just defer the update. Also, with |
Does having NodeModel call m_handler_notify_block_tip.disconnect() in its deconstructor fix the segfault? If you have a reliable way to cause the error I'd like to try. |
It's already called on the m_handler_notify_block_tip destructor. But that's not the issue, |
Sorry, I guess I don't remember a reason you couldn't EMIT the signal from another thread, I thought that setting the value and emitting the signal across threads was just fine and QML engine would handle the signal within its own thread but I'm fuzzy on the details. You are right about the handler deleting itself also. I doubled checked https://www.boost.org/doc/libs/1_57_0/doc/html/boost/signals2/scoped_connection.html. |
Github-Pull: bitcoin-core#177 Rebased-From: eca5252
Github-Pull: bitcoin-core#177 Rebased-From: eca5252
Github-Pull: bitcoin-core#177 Rebased-From: eca5252
This takes commit cf8a278 from #38 and rebases it over changes on master; namely that we've dropped
GUIUtil::ObjectInvoke
in favor ofQMetaObject::invokeMethod
.This avoids non-thread-safe errors. I ran into a segfault here while running some data intensive monkey-code related to blocks, this change prevented it. I'm not going to actually use the code that caused the segfault, just to illustrate that this is useful here anyways.