ForNeVeR / Cesium

C compiler for the CLI platform
MIT License
382 stars 42 forks source link

`StdIoFunctions.Handles` is not thread-safe and uses excessive resources #681

Closed ForNeVeR closed 1 week ago

ForNeVeR commented 3 weeks ago

Currently we use code such as this: https://github.com/ForNeVeR/Cesium/blob/d48d71e910ba319171a40e44966833bc691f1ce2/Cesium.Runtime/StdIoFunctions.cs#L532-L533

This is not thread safe and will break if several threads open files simultaneously.

Moreover, opening and closing a file will increment the Handles size by one and this will never decrement back.

This should be fixed — one way or another.

I propose us to migrate to some GCHandles to pin the file handle objects instead, and pass actual pointers to the app code. But we should see how to not miss the standard handles then.