Repository navigation
Fix lost events in ThreadAwareScheduler's thread queues #192
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
788f04f
Publish ThreadAwareScheduler queue entries with atomic indices
Simn c6ef5fe
Use WorkStealingQueue for ThreadAwareScheduler's thread queues
Simn db9e634
Fix the hxcpp build of WorkStealingQueue
Simn 4a01b06
Skip the yield burst test on neko
Simn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package schedulers; | ||
|
|
||
| // Not on neko: assigning a declared field for the first time adds it to the object, which is | ||
| // not safe while another thread reads the object. The thread pool shares continuations | ||
| // between threads like that, so this test fails there for reasons unrelated to the scheduler. | ||
| // See https://github.com/HaxeFoundation/neko/issues/335 | ||
| #if (target.threaded && !neko) | ||
| import hxcoro.run.LoopRun; | ||
| import hxcoro.run.Setup; | ||
| import sys.thread.Lock; | ||
| import sys.thread.Thread; | ||
| #end | ||
|
|
||
| class TestThreadAwareScheduler extends atest.Test { | ||
| #if (target.threaded && !neko) | ||
| /** | ||
| Pool threads schedule their `yield` resumptions into their own queues, which the loop | ||
| thread drains. The queue's indices used to be plain fields, so the loop thread could see | ||
| an advanced write index before the event itself, and lose the event. The run then hung. | ||
| On the JVM, this happened within a few rounds. | ||
|
|
||
| The rounds run on a separate thread, so a hang fails the test after a deadline instead | ||
| of blocking the test run. | ||
| **/ | ||
| function testYieldBurstsOnThreadPool() { | ||
| final rounds = #if (jvm || cpp) 100 #else 2 #end; | ||
| final yieldsPerTask = #if (jvm || cpp) 2000 #else 200 #end; | ||
| final done = new Lock(); | ||
| Thread.create(() -> { | ||
| for (_ in 0...rounds) { | ||
| final setup = Setup.createThreadPool(4); | ||
| LoopRun.runTask(setup.loop, setup.createContext(), node -> { | ||
| for (_ in 0...32) { | ||
| node.async(_ -> { | ||
| for (_ in 0...yieldsPerTask) { | ||
| yield(); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| setup.close(); | ||
| } | ||
| done.release(); | ||
| }); | ||
| Assert.isTrue(done.wait(60.0), "the run hung, so an event was lost"); | ||
| } | ||
| #else | ||
| function testNotSupported() { | ||
| Assert.pass(); | ||
| } | ||
| #end | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll review this again once we've dealt with HaxeFoundation/haxe#13095 properly.