add shutdown guard to profiler tests #46739
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's always been possible for managed code to continue running on background threads after EE shutdown, but the profiler tests have never needed to deal with it before because all the profilees were single threaded. That means that when the main method returned no more managed code would run.
Now that the managed thread pool is in place there can be background threads running managed code during shutdown. If something happens that triggers a call in to a profiler (ELT hook, JIT notification, etc) after shutdown, the test profiler will AV and fail the test due to trying to use a null ICorProfilerInfo*.
This adds synchronization so that the profile will block at shutdown if any runtime calls in the to profiler in progress, and then block future calls from doing anything.