-
Notifications
You must be signed in to change notification settings - Fork 0
Implement blocking loops instead of busy ones #106
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
Conversation
This reverts commit a367b16.
|
Something that's a little annoying about task.onCompletion((_, _) -> loop.wakeUp());
while (task.isActive()) {
loop.loop();
}We can hit the This actually explains some problems I've been seeing related to this. I've added a mutex to C++'s LuvScheduler to avoid issues with using handles from the callback after closing them from the loop-thread. But I wonder if there's a cleaner solution which avoids this situation entirely. |
|
And somehow despite the mutex, there's still the closed async problem on C++: |
|
Something must be wrong with (how I'm using) |
|
This works better now. The main problem was that I've been making a wrong assumption about when there can and cannot be events in the scheduler: just because a task is complete doesn't mean that the scheduler queue is necessarily empty. In particular, this can occur with cancellations where a scheduler handle remains in the scheduler's heap after closing it. The new test everyone hates is Issue124. JVM just got stuck and C++ ran into the Of course I can run the JVM tests locally 500 times in a row without any problems. The joy of multi-threaded programming... |
# Conflicts: # src/hxcoro/run/LoopRun.hx
|
This should be good now. C++ still randomly dies, but it does that on master too so that's not related. I don't love this Testing with a simple |

Here's my initial take on how to support this. I've opted to use a semaphore guarded by an atomic integer instead of a condition variable because I realized we would need a timed wait in order to have a basic "wait until the next event is due" functionality. This comes with the additional benefit of avoiding the signal-before-wait problem condition variables have. And another benefit is that the scheduling threads don't have to fight over a shared resource, they only do a single CAS in an attempt to update the atomic integer.
The
loopfunction inThreadAwareSchedulerlooks a little wonky now, but I think it does what I want it to do. I haven't actually checked if this does anything for the CPU on our threaded targets, for now I just want to get it to actually not hang everywhere.And just as I open this, HL decided to hang on
testAcquireConcurrency. That almost seems unrelated to what I'm doing here, but who knows...Edit: JVM hangs too, so basically this doesn't actually work yet.