mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
32 lines
1.0 KiB
Swift
32 lines
1.0 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-run-simple-swift(-parse-as-library -enable-experimental-feature Embedded -disable-availability-checking -wmo) | %FileCheck %s
|
|
|
|
// REQUIRES: swift_in_compiler
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: optimized_stdlib
|
|
// REQUIRES: synchronization
|
|
// REQUIRES: swift_feature_Embedded
|
|
|
|
import Synchronization
|
|
|
|
@main
|
|
struct Main {
|
|
static let x = Atomic(128)
|
|
|
|
static func main() {
|
|
let old = x.load(ordering: .relaxed)
|
|
x.store(42, ordering: .relaxed)
|
|
let new = x.load(ordering: .relaxed)
|
|
print(old) // CHECK: 128
|
|
print(new) // CHECK: 42
|
|
let old2 = x.exchange(12, ordering: .acquiring)
|
|
print(old2) // CHECK: 42
|
|
let (exchanged, original) = x.compareExchange(expected: 128, desired: 316, ordering: .sequentiallyConsistent)
|
|
print(exchanged) // CHECK: false
|
|
print(original) // CHECK: 12
|
|
let (exchanged2, original2) = x.compareExchange(expected: 12, desired: 316, ordering: .sequentiallyConsistent)
|
|
print(exchanged2) // CHECK: true
|
|
print(original2) // CHECK: 12
|
|
}
|
|
}
|