Skip to content

Slow thread suspension in busy loop #94767

Closed
@szehetner

Description

@szehetner

I have encountered a case where thread suspension before a GC takes multiple seconds (up to 70 seconds in the worst case). A minimal repro can be found here: https://gist.github.com/szehetner/47515ee0f28e2ca9d4990d60ac230a07

This starts a thread in a busy spin loop and triggers GCs. In a lot of iterations the GC takes multiple seconds. PerfView confirms that the time is spent during thread suspension:

image

Tested with .NET 7 and .NET 8 on x64 Windows - suspension times seem to be lower in .NET 8, but still significant.

My understanding is that it shouldn't be possible for user code to prevent thread suspension for such a long time. Is this an issue in the runtime? Or is there something I can do to speed up the suspension without giving up control of the thread (so without Thread.Yield() or Thread.Sleep())?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions