Skip to content

Commit dcd3c6f

Browse files
authored
Merge pull request swiftlang#36191 from apple/fix-actor_counters
Fix bug in actor_counters.swift test
2 parents 50390a5 + 6a7e7b0 commit dcd3c6f

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

test/Concurrency/Runtime/actor_counters.swift

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
// REQUIRES: concurrency
55
// REQUIRES: libdispatch
66

7-
// Remove with rdar://problem/72439642
8-
// UNSUPPORTED: asan
9-
107
#if canImport(Darwin)
118
import Darwin
129
#elseif canImport(Glibc)
@@ -19,6 +16,7 @@ actor Counter {
1916

2017
init(maxCount: Int) {
2118
scratchBuffer = .allocate(capacity: maxCount)
19+
scratchBuffer.initialize(repeating: 0)
2220
}
2321

2422
func next() -> Int {
@@ -34,10 +32,7 @@ actor Counter {
3432
}
3533

3634

37-
func worker(
38-
identity: Int, counters: [Counter], numIterations: Int,
39-
scratchBuffer: UnsafeMutableBufferPointer<Int>
40-
) async {
35+
func worker(identity: Int, counters: [Counter], numIterations: Int) async {
4136
for i in 0..<numIterations {
4237
let counterIndex = Int.random(in: 0 ..< counters.count)
4338
let counter = counters[counterIndex]
@@ -47,10 +42,6 @@ func worker(
4742
}
4843

4944
func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async {
50-
let scratchBuffer = UnsafeMutableBufferPointer<Int>.allocate(
51-
capacity: numCounters * numWorkers * numIterations
52-
)
53-
5445
// Create counter actors.
5546
var counters: [Counter] = []
5647
for i in 0..<numCounters {
@@ -63,10 +54,7 @@ func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async {
6354
workers.append(
6455
Task.runDetached { [counters] in
6556
usleep(UInt32.random(in: 0..<100) * 1000)
66-
await worker(
67-
identity: i, counters: counters, numIterations: numIterations,
68-
scratchBuffer: scratchBuffer
69-
)
57+
await worker(identity: i, counters: counters, numIterations: numIterations)
7058
}
7159
)
7260
}
@@ -76,8 +64,6 @@ func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async {
7664
try! await worker.get()
7765
}
7866

79-
// Clear out the scratch buffer.
80-
scratchBuffer.deallocate()
8167
print("DONE!")
8268
}
8369

0 commit comments

Comments
 (0)