Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scripting-mono-v2): allow scheduling from non-main threads #2423

Merged

Conversation

thorium-cfx
Copy link
Contributor

Goal of this PR

Enable scheduling tick calls from non-main threads, this is necessary to call back into the runtime (on the main thread) after external libraries used async/await with Task/Task<T> and we had nothing else scheduled. This didn't work before.

How is this PR achieving the goal

By removing its dependency on the Bookmark system (not thread-safe) and replacing it with a simplified version that achieves the same goal, but thread-safe.

This PR applies to the following area(s)

ScRT: C#

Successfully tested on

Server and client

Game builds: 2802

Platforms: Windows, Linux

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

fixes thorium-cfx/mono_v2_get_started#23

* Removes dependency on the Bookmark system, reverting previous changes.
* Remains tick-less, though in a different way, it's produces the same results with less work as the Bookmark system.
* Start using shared memory between C++ and C#, removing the need for unnecessary interop method calls and extra logic for timing.
* Remove leftover `Debug.Writeline`
@thorium-cfx thorium-cfx self-assigned this Mar 14, 2024
@github-actions github-actions bot added ScRT: C# Issues/PRs related to either C# scripting runtimes triage Needs a preliminary assessment to determine the urgency and required action labels Mar 14, 2024
Copy link
Contributor

@jakub-cfx jakub-cfx left a comment

Choose a reason for hiding this comment

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

Looks good to me 😊 Very nice and clean approach for a change that delivers such a big improvement. With the code already tested I think we can go ahead and merge.

@thorium-cfx thorium-cfx added ready-to-merge This PR is enqueued for merging and removed triage Needs a preliminary assessment to determine the urgency and required action labels Mar 19, 2024
@thorium-cfx thorium-cfx merged commit 5e71f91 into citizenfx:master Mar 19, 2024
6 checks passed
@thorium-cfx thorium-cfx deleted the fix/mono_rt2_async_scheduling branch April 18, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR is enqueued for merging ScRT: C# Issues/PRs related to either C# scripting runtimes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coroutines scheduled by non-main threads aren't scheduled in the core scheduler
2 participants