-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Console.Unix: avoid deadlock between LazyInitializer and Console.Out #34297
Conversation
Is this complex locking scheme really needed? Would it be better to just create the reader speculatively and let the first one win?
|
Yeah, I haven't looked at the change yet, but it's what I was thinking here: |
runtime/src/libraries/System.Console/src/System/ConsolePal.Unix.cs Lines 87 to 107 in 335ffb0
|
We would want to dispose of any instances that lost the race to be published. |
I've changed lazy initialization in Console to use |
The |
@stephentoub do you know why underlying |
I'm not sure what happens on Windows if you close a handle returned by GetStdHandle, and what implications that has on future attempts to use a future result from GetStdHandle; it's possible it stems from that, though I'm just guessing. On Unix we dup the file descriptors, so it should be fine to close them. |
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.
Thanks.
Co-Authored-By: Stephen Toub <stoub@microsoft.com>
@jkotas @danmosemsft @stephentoub thank you for thorough review! |
Thank you for your work @tmds. |
The change looks good to me. |
Re: fences. - There are about 20 uses of Volatile here. It'd be a scary piece of code if they were needed. That is something you expect every time you write an object that could be seen by other threads. |
This should be good to merge. |
Thanks, @tmds. |
Fixes #34197
@stephentoub ptal