none
GC.TryStartNoGCRegion() .NET garbage collection RRS feed

  • Question

  • GC.TryStartNoGCRegion() is a great concept to guarantee deterministic execution.

    My understanding of GC in .NET 4.5+ is each thread handles it's own GC context. This allows background GC so each thread can be suspended independently rather than suspending all threads at once.

    So is it possible to apply GC.TryStartNoGCRegion() to one thread at a time? It seems this would allow all threads to run GC as normal, except for the one "time critical" thread that GC.TryStartNoGCRegion() is applied to.

    Jas

    Direct Motion - http://www.directmotion.com

    Monday, May 25, 2015 11:22 PM

Answers

  • "My understanding of GC in .NET 4.5+ is each thread handles it's own GC context"

    Sort of, there is an allocation context which is basically a small amount of memory from which the thread can quickly allocate without requiring locks to synchronize with other threads. But once that small amount of memory is exhausted the thread has to go the main GC heap to get another block of memory for its allocation context.

    "So is it possible to apply GC.TryStartNoGCRegion() to one thread at a time?"

    As far as I can tell from the CLR GC source that isn't possible, TryStartNoGCRegion affects all threads.

    Tuesday, May 26, 2015 3:56 PM
    Moderator