-
Notifications
You must be signed in to change notification settings - Fork 819
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
Conversation
@@ -89,12 +89,13 @@ public class Glob: Collection { | |||
} | |||
|
|||
let patterns = behavior.supportsGlobstar ? expandGlobstar(pattern: adjustedPattern) : [adjustedPattern] | |||
|
|||
|
|||
let isIncludingFiles = includeFiles |
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.
This closure made @Sendable
closure, so it's better to avoid passing mutable variables
var buffer = ContiguousArray<T?>(repeating: nil, count: count) | ||
DispatchQueue.concurrentPerform(iterations: count) { idx in | ||
buffer[idx] = transform(self[idx]) | ||
} | ||
return buffer.map { $0! } |
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.
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]) |
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.
This implementation is dangerous, it may cause a race-condition...
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. |
This issue seems to be fixed on Beta 6 |
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 toSendable
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