I was fixing MT codegen in Crystal (see #14748) and noticed it had a pitfall (starving threads because of blocked fiber) that could be solved by using execution contexts.
I thus went to try it out, and I quickly identified an issue in the execution contexts: the process eventually comes to a halt :raised_eyebrow:
The DEFAULT thread (ST) whose main thread is sending to a channel is waiting on the event loop, while the CODEGEN threads wait to read on an empty channel (with no pending sender). A debug sessions showed that the main fiber was properly enqueued in the global queue of the DEFAULT thread, but the thread is still waiting on the event loop.
That MUSN'T happen. There's a race condition that fails to interrupt or fails to prevent a thread from blocking on the event loop.
I was fixing MT codegen in Crystal (see #14748) and noticed it had a pitfall (starving threads because of blocked fiber) that could be solved by using execution contexts.
I thus went to try it out, and I quickly identified an issue in the execution contexts: the process eventually comes to a halt :raised_eyebrow:
The DEFAULT thread (ST) whose main thread is sending to a channel is waiting on the event loop, while the CODEGEN threads wait to read on an empty channel (with no pending sender). A debug sessions showed that the main fiber was properly enqueued in the global queue of the DEFAULT thread, but the thread is still waiting on the event loop.
That MUSN'T happen. There's a race condition that fails to interrupt or fails to prevent a thread from blocking on the event loop.