Skip to content

Commit f54ff7f

Browse files
authored
Merge pull request #25669 from apple/deflake-test-tsan-libdispatch
[TSan] Deflake positive TSan+libdispatch test
2 parents 47a62c0 + f6d869f commit f54ff7f

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

test/Sanitizers/tsan-libdispatch.swift

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,43 @@
99
// don't support TSan.
1010
// UNSUPPORTED: remote_run
1111

12-
// rdar://51730684
13-
// REQUIRES: disable
14-
1512
// Test ThreadSanitizer execution end-to-end with libdispatch.
1613

1714
import Dispatch
1815

16+
let q = DispatchQueue(label: "q", attributes: .concurrent)
17+
1918
let sync1 = DispatchSemaphore(value: 0)
2019
let sync2 = DispatchSemaphore(value: 0)
2120
let finish = DispatchSemaphore(value: 0)
2221

23-
let q = DispatchQueue(label: "q", attributes: .concurrent)
24-
25-
var racy = 1
26-
27-
q.async {
28-
sync1.wait()
29-
sync2.signal()
30-
racy = 2
31-
finish.signal()
32-
}
33-
q.async {
34-
sync1.signal()
35-
sync2.wait()
36-
racy = 3
37-
finish.signal()
22+
func wait1_signal2() { sync1.wait(); sync2.signal() }
23+
func signal1_wait2() { sync1.signal(); sync2.wait() }
24+
25+
func race() {
26+
var racy = 1
27+
28+
q.async {
29+
wait1_signal2()
30+
racy = 2
31+
wait1_signal2()
32+
finish.signal()
33+
}
34+
q.async {
35+
signal1_wait2()
36+
racy = 3
37+
signal1_wait2()
38+
finish.signal()
39+
}
40+
41+
finish.wait()
42+
finish.wait()
3843
}
3944

40-
finish.wait()
41-
finish.wait()
45+
// TSan %deflake as part of the test.
46+
for _ in 1...10 {
47+
race()
48+
}
4249

4350
print("Done!")
4451

test/Sanitizers/tsan.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public func call_foobar() {
4444
var threads: [pthread_t] = []
4545
var racey_x: Int;
4646

47+
// TSan %deflake as part of the test.
4748
for _ in 1...5 {
4849
#if os(macOS) || os(iOS)
4950
var t : pthread_t?

0 commit comments

Comments
 (0)