Skip to content

Commit 57217f3

Browse files
authored
Merge pull request #1158 from lorentey/se-0282-accepted
Mark SE-0282 as accepted and apply core team's notes
2 parents 1743439 + 93191a3 commit 57217f3

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

proposals/0282-atomics.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# Interoperability with the C Atomic Operations Library ⚛︎
1+
# Clarify the Swift memory consistency model ⚛︎
22

33
* Proposal: [SE-0282](0282-atomics.md)
44
* Author: [Karoy Lorentey](https://github.com/lorentey)
55
* Review Manager: [Joe Groff](https://github.com/jckarter)
66
* Bug: [SR-9144](https://bugs.swift.org/browse/SR-9144)
77
* Implementation: Proof of concept [swift-atomics package][package]
88
* Previous Revision: [v1][SE-0282v1] ([Returned for revision](https://forums.swift.org/t/se-0282-low-level-atomic-operations/35382/69))
9-
* Status: **Active review (June 8...June 25, 2020)**
9+
* Status: **Implemented (Swift 5.3)**
10+
* Decision Notes: [Rationale](https://forums.swift.org/t/accepted-se-0282-interoperability-with-the-c-atomic-operations-library/38050)
1011

1112
[SE-0282v1]: https://github.com/apple/swift-evolution/blob/3a358a07e878a58bec256639d2beb48461fc3177/proposals/0282-atomics.md
1213
[package]: https://github.com/apple/swift-se-0282-experimental
@@ -65,6 +66,9 @@ When applied carefully, atomic operations and memory ordering constraints can be
6566

6667
For now, we will be heavily relying on the Law of Exclusivity as defined in [[SE-0176]] and the [[Ownership Manifesto]], and we'll explain to what extent C's memory orderings apply to Swift's variable accesses. The intention is that Swift's memory model will be fully interoperable with its C/C++ counterparts.
6768

69+
This proposal does not specify whether/how dependency chains arising from the C/C++ `memory_order_consume` memory ordering work in Swift. The consume ordering as specified in the C/C++ standards is not implemented in any C/C++ compiler, and we join the current version of the C++ standard in encouraging Swift programmers not to use it. We expect to tackle the problem of efficient traversal of concurrent data structures in future proposals. Meanwhile, Swift programmers can start building useful concurrency constructs using relaxed, acquire/release, and sequentially consistent memory orderings imported from C.
70+
71+
6872
### Amendment to The Law of Exclusivity
6973

7074
While the declarations in C's `stdatomic.h` header don't directly import into Swift, it is still possible to access these constructs from Swift code by [wrapping them into plain structs and functions][package] that can be imported. This way, `_Atomic` values can end up being stored within a Swift variable.
@@ -80,18 +84,18 @@ To resolve this problem, we propose to introduce the concept of *atomic access*,
8084
We define *atomic access* as a call to one of the following functions in the C atomic operation library:
8185

8286
```text
83-
atomic_flag_test_and_set atomic_flag_test_and_set_explicit
84-
atomic_flag_clear atomic_flag_clear_explicit
85-
atomic_store atomic_store_explicit
86-
atomic_load atomic_load_explicit
87-
atomic_exchange atomic_exchange_explicit
88-
atomic_compare_exchange_strong atomic_compare_exchange_strong_explicit
89-
atomic_compare_exchange_weak atomic_compare_exchange_weak_explicit
90-
atomic_fetch_add atomic_fetch_add_explicit
91-
atomic_fetch_sub atomic_fetch_sub_explicit
92-
atomic_fetch_or atomic_fetch_or_explicit
93-
atomic_fetch_xor atomic_fetch_xor_explicit
94-
atomic_fetch_and atomic_fetch_and_explicit
87+
atomic_flag_test_and_set atomic_flag_test_and_set_explicit
88+
atomic_flag_clear atomic_flag_clear_explicit
89+
atomic_store atomic_store_explicit
90+
atomic_load atomic_load_explicit
91+
atomic_exchange atomic_exchange_explicit
92+
atomic_compare_exchange_strong atomic_compare_exchange_strong_explicit
93+
atomic_compare_exchange_weak atomic_compare_exchange_weak_explicit
94+
atomic_fetch_add atomic_fetch_add_explicit
95+
atomic_fetch_sub atomic_fetch_sub_explicit
96+
atomic_fetch_or atomic_fetch_or_explicit
97+
atomic_fetch_xor atomic_fetch_xor_explicit
98+
atomic_fetch_and atomic_fetch_and_explicit
9599
```
96100

97101
We consider two of these operations to *access the same variable* if they operate on the same memory location. (Future proposals may introduce additional ways to perform atomic access, including native support for atomic operations in the Swift Standard Library.)

0 commit comments

Comments
 (0)