-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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.CursorTop blocks on Linux when ReadKey is called from another thread #34239
Comments
This is a 'known' limitation: runtime/src/libraries/System.Console/src/System/ConsolePal.Unix.cs Lines 479 to 482 in e85e352
The thread performing the
It doesn't occur when |
Is this related somehow? |
No. This is effectively by design, as @tmds outlined. The only reasonable way of getting the current cursor position on Unix is by writing an escape sequence to stdout requesting the position, and reading from stdin the response sent by the terminal. We have to lock around that, or else concurrent reads might end up reading the terminal's response, which would a) be gibberish and b) break the request/response protocol. That does mean if another thread is blocked on reading the console, a call to get the current position will block until the first read completes, unless we have a position cached. |
This happens on 3.1.101. It seems to be dependent on the order of calls, because if CursorTop is accessed at least once from
printThread
in the following code before ReadKey is called from the main thread, this issue does not occur. This can be tested by passing1
as the argument to the repro code. I could not reproduce this on Windows (although I'm using a different machine for it).This produces the following output on Linux:
Machine info:
The text was updated successfully, but these errors were encountered: