When debugging inside WSL, a single thread running an infinite loop appears to completely block the main thread from execution.
Reproduction Steps
In Visual Studio, create a new console project with this code:
Console.WriteLine("Started");
new Thread(() =>
{
while (true){}
}).Start();
while (true)
{
Console.WriteLine("Main thread");
Thread.Sleep(1000);
}
Then run on the WSL2 debugging target (if you don't see it, follow the steps).
Expected behavior
"Main thread" appears approximately once per second, indefinitely.
Actual behavior
"Main thread" appears 5 times (it appears to be exactly 5 every time) then stops indefinitely.
Regression?
No response
Known Workarounds
Modifying the loop to include Thread.Sleep(0) appears to work around the issue. Running the project on the Windows target or directly inside WSL2 does not show the issue either.
Configuration
Tested on Windows 11 (latest build) on x64, Visual Studio 17.8, happens on both .NET 8 and .NET 7, using both Ubuntu and OpenSUSE as the WSL distros.
Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.
Issue Details
### Description
When debugging inside WSL, a single thread running an infinite loop appears to completely block the main thread from execution.
### Reproduction Steps
In Visual Studio, create a new console project with this code:
```c#
Console.WriteLine("Started");
new Thread(() =>
{
while (true){}
}).Start();
while (true)
{
Console.WriteLine("Main thread");
Thread.Sleep(1000);
}
```
Then run on the WSL2 debugging target (if you don't see it, [follow the steps](https://learn.microsoft.com/en-us/visualstudio/debugger/debug-dotnet-core-in-wsl-2?view=vs-2022)).
### Expected behavior
"Main thread" appears approximately once per second, indefinitely.
### Actual behavior
"Main thread" appears 5 times (it appears to be exactly 5 every time) then stops indefinitely.
### Regression?
_No response_
### Known Workarounds
Modifying the loop to include `Thread.Sleep(0)` appears to work around the issue. Running the project on the Windows target or directly inside WSL2 does not show the issue either.
### Configuration
Tested on Windows 11 (latest build) on x64, Visual Studio 17.8, happens on both .NET 8 and .NET 7, using both Ubuntu and OpenSUSE as the WSL distros.
### Other information
A similar case appears to have been reported here: [c# - Threads with low priority prevents other threads with normal priority from execution - Stack Overflow](https://stackoverflow.com/questions/62809155/threads-with-low-priority-prevents-other-threads-with-normal-priority-from-execu)
Description
When debugging inside WSL, a single thread running an infinite loop appears to completely block the main thread from execution.
Reproduction Steps
In Visual Studio, create a new console project with this code:
Then run on the WSL2 debugging target (if you don't see it, follow the steps).
Expected behavior
"Main thread" appears approximately once per second, indefinitely.
Actual behavior
"Main thread" appears 5 times (it appears to be exactly 5 every time) then stops indefinitely.
Regression?
No response
Known Workarounds
Modifying the loop to include
Thread.Sleep(0)
appears to work around the issue. Running the project on the Windows target or directly inside WSL2 does not show the issue either.Configuration
Tested on Windows 11 (latest build) on x64, Visual Studio 17.8, happens on both .NET 8 and .NET 7, using both Ubuntu and OpenSUSE as the WSL distros.
Other information
A similar case appears to have been reported here: c# - Threads with low priority prevents other threads with normal priority from execution - Stack Overflow