Files
swift-mirror/test/embedded/exclusivity_runtime_multi.swift
Doug Gregor c24a4c399e [Embedded tests] Drop redundant shim substitutions on %target-embedded-link
`%target-embedded-link` now bundles `libswiftCore.a` (and
`libswiftEmbeddedPlatformPOSIX.a` when available), so RUN lines that spell
out `%target-embedded-posix-shim` or `%embedded-stdlib` alongside it are
redundant.

Also switch `concurrency-dynamic-isolation-link.swift` from raw
`%target-clang` to `%target-embedded-link` so it picks up the stdlib archive
through the same substitution.
2026-07-13 23:27:19 -07:00

71 lines
1.8 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library %s -c -o %t/a.o -enforce-exclusivity=checked -enable-experimental-feature EmbeddedDynamicExclusivity
// Multi-threaded exclusivity checking implementation (that uses C11 thread_local).
// RUN: %target-embedded-link %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%module-target-triple %target-clang-resource-dir-opt -lswift_Concurrency %target-swift-default-executor-opt -dead_strip -lswiftExclusivityC11ThreadLocal
// RUN: %target-run not --crash %t/a.out
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: swift_feature_Embedded
// REQUIRES: swift_feature_EmbeddedDynamicExclusivity
// UNSUPPORTED: OS=wasip1
// UNSUPPORTED: OS=emscripten
// libswiftExclusivityC11ThreadLocal.a links no symbols on emscripten because
// C11 `_Thread_local` is gated out for its musl-derived libc
// (`wasm-ld: error: undefined symbol: _swift_{get,set}ExclusivityTLS`).
struct NC: ~Copyable {
var i: Int = 1
mutating func add(_ other: borrowing Self) {
i += other.i
i += other.i
print(self.i)
print(other.i)
}
}
class C1 {
var nc = NC()
func foo() {
nc.add(nc)
}
}
struct S {
var i: Int = 1
mutating func add(_ c: C2) {
let other = c.getS()
i += other.i
i += other.i
print(self.i)
print(other.i)
}
}
final class C2 {
var s = S()
@inline(never)
func getS() -> S { s }
func foo() {
s.add(self)
}
}
@main
struct Main {
static func main() {
// Note: not actually checked because it doesn't get flushed.
// CHECK: Simultaneous access to 0x{{.*}}, but modification requires exclusive access
// CHECK: Previous access (a modify) started at 0x{{.*}}
// CHECK: Current access (a read) started at 0x{{.*}}
C1().foo()
}
}