Skip to content

Commit

Permalink
Fix class construction recursion issue in Lock on NativeAOT
Browse files Browse the repository at this point in the history
- The `Monitor` type was being constructed due to the use of `Monitor.DebugBlockingScope`, added that to the initialization phase
- If necessary, an alternative may be to move `DebugBlockingScope` to be under `Lock`. Based on the comments the thread-static field is apparently bound-to in debugging scenarios.
- Fixes dotnet#94227
  • Loading branch information
kouvel committed Oct 31, 2023
1 parent ac95ec9 commit dd9246a
Showing 1 changed file with 1 addition and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private static bool TryInitializeStatics()

// Also initialize some types that are used later to prevent potential class construction cycles
NativeRuntimeEventSource.Log.IsEnabled();
using (new Monitor.DebugBlockingScope(null, Monitor.DebugBlockingItemType.MonitorCriticalSection, 0, out _)) { }
}
catch
{
Expand Down

0 comments on commit dd9246a

Please sign in to comment.