Skip to content
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

Make asyncMap to prevent from race-condition #1492

Closed
wants to merge 4 commits into from

Conversation

giginet
Copy link
Collaborator

@giginet giginet commented Aug 7, 2024

closes #1491
Build failure due to concurrency issue since Xcode 16 Beta 5 · Issue #1491 · yonaskolb/XcodeGen

The current main can't build with Xcode 16 Beta 5.
Because, UnsafeMutableBudderPointer is not a thread-safe, so we can't pass it to Sendable closure even if compiled in Swift 5 mode.

This PR resolves this issue.

This change may cause the performance, but I have no idea how much not using ContiguousArray will affect performance

@@ -89,12 +89,13 @@ public class Glob: Collection {
}

let patterns = behavior.supportsGlobstar ? expandGlobstar(pattern: adjustedPattern) : [adjustedPattern]


let isIncludingFiles = includeFiles
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This closure made @Sendable closure, so it's better to avoid passing mutable variables

Comment on lines +6 to +10
var buffer = ContiguousArray<T?>(repeating: nil, count: count)
DispatchQueue.concurrentPerform(iterations: count) { idx in
buffer[idx] = transform(self[idx])
}
return buffer.map { $0! }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab/space is not unified

func parallelMap<T>(transform: @Sendable (Element) -> T) -> [T] {
var buffer = ContiguousArray<T?>(repeating: nil, count: count)
DispatchQueue.concurrentPerform(iterations: count) { idx in
buffer[idx] = transform(self[idx])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is dangerous, it may cause a race-condition...

@giginet
Copy link
Collaborator Author

giginet commented Aug 7, 2024

This PR seems to pass the test and builds, but I'm concerned that this change is breaking thread-safe... 🤔

The best solution is to replace the modern concurrency mechanism, but it's tough to introduce Swift Concurrency to this project.

@giginet
Copy link
Collaborator Author

giginet commented Aug 21, 2024

This issue seems to be fixed on Beta 6

@giginet giginet closed this Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure due to concurrency issue since Xcode 16 Beta 5
2 participants