TASEmulators / TASEmulators/BizHawk
[🐧] BizInvoker does not cause gc mode switch without compatibility argument
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.8k
- Forks
- 468
- PR merge metrics
- No merged PRs in 30d
Description
Calling a [BizImport]ed function that doesn't use Compatibility = true will not cause a gc mode change.
This is relevant because mono relies on each thread having the correct gc mode to perform garbage collection effectively. If a thread is assumed to be in gc unsafe mode (executing managed code), the garbage collector will wait for the thread to reach a safe point and suspend itself so garbage collection can be performed, but if an unmanaged function is being executed this safe point will only be reached once the function returns back to managed code, which may never happen. This initially came up in #4117 where garbage collection would deadlock the entire program because garbage collection was waiting on the core thread to suspend itself while the core thread was waiting on a command from the frontend (while the frontend thread was already suspended).
Aside from the possibility to cause deadlocks this might also negatively affect performance across the board because gc's are being stalled while such functions are being executed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing BizInvoker calls for [BizImport]ed functions without Compatibility = true, then inspect how GC mode changes around managed and unmanaged execution. Done means those invocations put each thread in the correct GC mode and the deadlock scenario described in #4117 no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100