Skip to content

fix: Prepare ThreadPool for .Net11+ - #3351

Open
Eideren wants to merge 1 commit into
stride3d:masterfrom
Eideren:tp11
Open

fix: Prepare ThreadPool for .Net11+#3351
Eideren wants to merge 1 commit into
stride3d:masterfrom
Eideren:tp11

Conversation

@Eideren

@Eideren Eideren commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

PR Details

See #3326
Very minor changes to the dispatcher as well to make the logic a bit more readable and reduce the cruft.

Related Issue

fixes #3326

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

@Eideren Eideren added the area-Core Issue of the engine unrelated to other defined areas label Aug 11, 2026
{
// The semaphore Dotnet uses for its own threadpool is more efficient than what's publicly available,
// but sadly it is internal - we'll hijack it through reflection
Type lifoType = Type.GetType("System.Threading.LowLevelLifoSemaphore")!;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we copy/paste the code instead?
Reflection doesn't necessarily work on all platforms and it certainly won't if we ever support Native AOT.

@Ethereal77 Ethereal77 Aug 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we end up copying it, I'd wait for the final release of .NET 11, or else we are obligued to watch if they ever change it, correct bugs, redesign it, etc. (which may very well happen since it's still in preview)

Edit: ...or at least the RC

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we copy/paste the code instead? Reflection doesn't necessarily work on all platforms and it certainly won't if we ever support Native AOT.

FYI, we do support Native AOT already since PR #3204 (not only for iOS but also desktop).
It's even tested regularly.

@Kryptos-FR Kryptos-FR Aug 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did the tests no fail in such case? Or is it not part of tests triggered by PR changes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AOT does support reflection, it doesn't support generating new IL on the fly, so no generics like Type.MakeGenericType() basically

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I remember, you need to be able to access the type of the class you want to access through that API, here the type is internal

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I remember, you need to be able to access the type of the class you want to access through that API, here the type is internal

That's only true on .NET 9 and lower.

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafeaccessortypeattribute?view=net-10.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AOT does support reflection, it doesn't support generating new IL on the fly, so no generics like Type.MakeGenericType() basically

Yes. I think in my mind I had a simpler rule about reflection because in some cases, the related types could have been trimmed. However, in the present case, it's part of the framework so unlikely to be trimmed.

Maybe there is no issue after all.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ds5678 cool stuff, thanks! Do you happen to know whether there is a way to validate unsafe accessor mappings without running them - we need to know whether those method exist for the fallback, I could call them with a null instance and filter based on if I get a nullref exception but that's... kind of awful

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the target member cannot be found, I think the runtime implements it as throwing MissingMethodException (or similar).

I don't know of any way to check if a method is available other than with a try catch block and caching the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Core Issue of the engine unrelated to other defined areas

Projects

None yet

Development

Successfully merging this pull request may close these issues.

regression: LowLevelLifoSemaphore change in signature in dotnet11

5 participants