-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
ConcurrencуArea → standard library: The `Concurrency` module under the standard library umbrellaArea → standard library: The `Concurrency` module under the standard library umbrellabugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language featuresFeature: umbrella label for concurrency language featuresstandard libraryArea: Standard library umbrellaArea: Standard library umbrellaswift 6.0unexpected behaviorBug: Unexpected behavior or incorrect outputBug: Unexpected behavior or incorrect output
Description
Description
From this discussion: https://forums.swift.org/t/task-executor-preference-and-deterministic-scheduling/72448
Reproduction
final class MainExecutor: TaskExecutor {
func enqueue(_ job: consuming ExecutorJob) {
job.runSynchronously(
isolatedTo: MainActor.sharedUnownedExecutor,
taskExecutor: asUnownedTaskExecutor()
)
}
}
func testSerializedExecution_YieldEveryOtherValue() async {
let xs = Mutex<[Int]>([])
await withTaskExecutorPreference(MainExecutor()) {
await withTaskGroup(of: Void.self) { group in
for x in 1...1000 {
group.addTask { @Sendable in // Explicit `@Sendable` required in Xcode 16 due to new `sending` keyword
if x.isMultiple(of: 2) { await Task.yield() }
xs.withLock { $0.append(x) }
}
}
}
}
XCTAssertEqual(
(0...499).map { $0 * 2 + 1 } + (1...500).map { $0 * 2 },
xs.withLock { $0 }
)
}
Expected behavior
I expect the test to pass.
Environment
swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0
Additional information
No response
0xpablo, dehesa, jasikpark and erikbasargin
Metadata
Metadata
Assignees
Labels
ConcurrencуArea → standard library: The `Concurrency` module under the standard library umbrellaArea → standard library: The `Concurrency` module under the standard library umbrellabugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language featuresFeature: umbrella label for concurrency language featuresstandard libraryArea: Standard library umbrellaArea: Standard library umbrellaswift 6.0unexpected behaviorBug: Unexpected behavior or incorrect outputBug: Unexpected behavior or incorrect output