Skip to content

Commit a85aede

Browse files
committed
[Exclusivity] Add test for per-thread dynamic enforcement.
We intentionally do not trap on conflicting accesses from different threads. This is a test-only change.
1 parent 73aabd7 commit a85aede

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/Interpreter/enforce_exclusive_access.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Tests for traps at run time when enforcing exclusive access.
99

1010
import StdlibUnittest
11+
import SwiftPrivatePthreadExtras
1112

1213
struct X {
1314
var i = 7
@@ -108,6 +109,18 @@ ExclusiveAccessTestSuite.test("ClosureCaptureModifyModify") {
108109
}
109110
}
110111

112+
// Test for per-thread enforcement. Don't trap when two different threads
113+
// have overlapping accesses
114+
ExclusiveAccessTestSuite.test("PerThreadEnforcement") {
115+
modifyAndPerform(&globalX) {
116+
var (_, otherThread) = _stdlib_pthread_create_block(nil, { (_ : Void) -> () in
117+
globalX.i = 12 // no-trap
118+
return ()
119+
}, ())
120+
121+
_ = _stdlib_pthread_join(otherThread!, Void.self)
122+
}
123+
}
111124

112125

113126

0 commit comments

Comments
 (0)