Skip to content

[Swift] Changes to Mutex-es to guard the staticly shared [DFA] - #3276

Merged
parrt merged 4 commits into
antlr:masterfrom
martinvw:feature/issue-3271-fix-mutex
Sep 28, 2021
Merged

parrt merged 4 commits into
antlr:masterfrom
martinvw:feature/issue-3271-fix-mutex

Conversation

@martinvw

Copy link
Copy Markdown
Contributor

Request for review: @janyou, @ewanmellor, @hanjoes, @rmehta33

By sharing the mutex in the same way as the DFA array it becomes possible to run in parallel

Fixes #3271

By sharing the mutex in the same way as the DFA array it becomes possible to run in parallel

Added a test in ThreadingTests

Fixes: 3271
Signed-off-by: Martin van Wingerden <martin@martinvw.nl>
@martinvw martinvw mentioned this pull request Sep 14, 2021
2 tasks done
@martinvw martinvw changed the title Changes to Mutex-es to guard the staticly shared [DFA] [Swift] Changes to Mutex-es to guard the staticly shared [DFA] Sep 14, 2021
@ericvergnaud

Copy link
Copy Markdown
Contributor

Hi,

this sounds useful but I'm not sure your test is 'hungry' enough to prove that it works.
there is a genuine possibility that the first iteration ends before the second one starts,
plus they both generate the same DFA enrichment so might be missing important scenarios.
May I suggest that you try parsing longer and different inputs in parallel such that the test does proves that it works in the problematic scenarios too ?

@martinvw

Copy link
Copy Markdown
Contributor Author

Without my changes this test always fails and with it always succeeds. I do believe we should aim for a bit more code coverage but I doubt that multiple or much more complex grammar is needed, however a longer text of course make sense.

I do not completely understand the second part of your comment, I might need a hint about that one.

Thanks for your time!

@ericvergnaud

ericvergnaud commented Sep 25, 2021 via email

Copy link
Copy Markdown
Contributor

@martinvw

martinvw commented Sep 25, 2021 via email

Copy link
Copy Markdown
Contributor Author

Signed-off-by: Martin van Wingerden <martin@martinvw.nl>
@martinvw

martinvw commented Sep 27, 2021 •

Copy link
Copy Markdown
Contributor Author

@ericvergnaud I updated the test with a bit more complex expressions, do you think this would be enough:

func testParallelExecution() throws {
let input = [
"2 * 8 - 4",
"2 + 8 / 4",
"2 - 8 - 4",
"2 * 8 * 4",
"2 / 8 / 4",
"2 + 8 + 4",
"890",
]
let expectation = expectation(description: "Waiting on async-task")
expectation.expectedFulfillmentCount = 77
for i in 0...77 {
DispatchQueue.global().async {
let lexer = ThreadingLexer(ANTLRInputStream(input[i % 7]))
let tokenStream = CommonTokenStream(lexer)
let parser = try? ThreadingParser(tokenStream)
let _ = try? parser?.s()
expectation.fulfill()
}
}

I checked the call trace and I see that we actually touch all the changed files with the current test, so that looks good.

EDIT: I checked instead of check, so it is already done.

Signed-off-by: Martin van Wingerden <martin@martinvw.nl>
Signed-off-by: Martin van Wingerden <martin@martinvw.nl>
@ericvergnaud

Copy link
Copy Markdown
Contributor

@parrt blessed, the failing test is unrelated and is fixed through another PR

@parrt
parrt merged commit 886d244 into antlr:master Sep 28, 2021
@martinvw

Copy link
Copy Markdown
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swift Target Crashes with Multi-Threading

3 participants