Does the .NET Garbage Collector increase stop-the-world or slow down unmanaged threads and timer callbacks?

I have an application that needs to have code executed at very precise intervals. For this, I also need the Windows Scheduler permission to increase to 1 ms through timeBeginPeriod .

For this, I have a native C ++ dll that processes all critical time points through callbacks that arise from TimerQueueTimer with an interval of 1 ms (all native code).

The application itself is a .NET application (C #, therefore pure CLR). The native DLL uses buffering, so C # code itself should not be time critical until it receives some runtime every 50 ms or so.

When the garbage collector strikes, will it also stop or delay the execution of any timer callbacks in my program? (In other words: the non-determinism of a .NET program even extends to its own code fragments used by it?) I did not find the answer to this exact question. A link to the MSDN documentation will be most encouraging.

I am using .NET 4.0

+6
source share
1 answer

My intuition says no - the CLR only affects managed threads.

  • CLR garbage collection does not need to stop unmanaged threads.
  • The CLR does not need to know threads other than the CLR in the process: this will break the isolation. Think of an IIS server or SQL server - with both the CLR and the CLR, but I can’t imagine that the CLR freezes all threads in the process ... Even if the WIN32 API functions are used by user-managed code (stored-proc / web application), in order to try to manipulate unmanaged threads in a process, managed code located on the hosting should not even have the security permissions necessary to manage flows of a non-CLR host (for Windows, the CLR is “another COM object”).

I can’t find the MSDN confirmation, but you can try to prove that the unmanaged stream works during garbage collection: constantly monitor the unmanaged stream and the GC notification mechanism . See that managed flow tracing continues during the garbage collection process.

(It’s also worth noting that there are several GC “modes” that behave differently)

+3
source

Source: https://habr.com/ru/post/945448/


All Articles