forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsan-norace-deinit-run-time.swift
52 lines (42 loc) · 1.15 KB
/
tsan-norace-deinit-run-time.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// RUN: %target-swiftc_driver %s -g -sanitize=thread -o %t_tsan-binary
// RUN: env TSAN_OPTIONS=abort_on_error=0:ignore_interceptors_accesses=1 %target-run %t_tsan-binary 2>&1 | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: objc_interop
// REQUIRES: CPU=x86_64
// REQUIRES: tsan_runtime
// XFAIL: linux
// Test that we do not report a race on deinit; the synchronization is guaranteed by runtime.
import Foundation
public class TestDeallocObject : NSObject {
public var v : Int
public override init() {
v = 1
}
@_semantics("optimize.sil.never")
func unoptimize(_ input : Int) -> Int {
return input
}
func accessMember() {
var local : Int = unoptimize(v)
local += 1
}
deinit {
v = 0
}
}
if (true) {
var tdo : TestDeallocObject = TestDeallocObject()
tdo.accessMember()
// Read the value from a different thread.
let concurrentQueue = DispatchQueue(label: "queuename", attributes: .concurrent)
concurrentQueue.async {
tdo.accessMember()
}
// Read the value from this thread.
tdo.accessMember()
sleep(1)
// Deinit the value.
}
print("Done.")
// CHECK: Done.
// CHECK-NOT: ThreadSanitizer: data race