4
4
// REQUIRES: concurrency
5
5
// REQUIRES: libdispatch
6
6
7
- // Remove with rdar://problem/72439642
8
- // UNSUPPORTED: asan
9
-
10
7
#if canImport(Darwin)
11
8
import Darwin
12
9
#elseif canImport(Glibc)
@@ -19,6 +16,7 @@ actor Counter {
19
16
20
17
init ( maxCount: Int ) {
21
18
scratchBuffer = . allocate( capacity: maxCount)
19
+ scratchBuffer. initialize ( repeating: 0 )
22
20
}
23
21
24
22
func next( ) -> Int {
@@ -34,10 +32,7 @@ actor Counter {
34
32
}
35
33
36
34
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 {
41
36
for i in 0 ..< numIterations {
42
37
let counterIndex = Int . random ( in: 0 ..< counters. count)
43
38
let counter = counters [ counterIndex]
@@ -47,10 +42,6 @@ func worker(
47
42
}
48
43
49
44
func runTest( numCounters: Int , numWorkers: Int , numIterations: Int ) async {
50
- let scratchBuffer = UnsafeMutableBufferPointer< Int> . allocate(
51
- capacity: numCounters * numWorkers * numIterations
52
- )
53
-
54
45
// Create counter actors.
55
46
var counters : [ Counter ] = [ ]
56
47
for i in 0 ..< numCounters {
@@ -63,10 +54,7 @@ func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async {
63
54
workers. append (
64
55
Task . runDetached { [ counters] in
65
56
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)
70
58
}
71
59
)
72
60
}
@@ -76,8 +64,6 @@ func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async {
76
64
try ! await worker. get ( )
77
65
}
78
66
79
- // Clear out the scratch buffer.
80
- scratchBuffer. deallocate ( )
81
67
print ( " DONE! " )
82
68
}
83
69
0 commit comments