-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Better Debug for Mutex #2725
Better Debug for Mutex #2725
Conversation
Same should be done for RwLock, but it misses try_read method currently. |
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.
I'm definitely in favor of making the formatted output more user-friendly.
I had a couple notes on changes we might want to make for consistency with how std::sync::Mutex
implements Debug
. What do you think?
@hawkw thanks for your review! I've made both improvements and added a test. |
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.
Looks good to me!
Motivation
Before it looked like
which is quite useless.
New output is
Where X is determined by locking the mutex. If we succeed, we call Debug for inner valuer. Otherwise,
X := "<locked>"
.IMO proposed Debug output is strictly better than current.
Alternative: always lock mutex and show inner value. However, such behavior can be rather unexpected so I implemented something more conservative.