You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-40Lines changed: 69 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ The primary focus is to provide systems programmers access to atomic operations
47
47
48
48
- Each atomic operation is invoked in client code using a clear, unabbreviated name that directly specifies what that operation does. Atomic operations are never implicit -- they are always clearly spelled out.
49
49
50
-
- There is no default memory ordering, to avoid accidental (and costly) use of sequential consistency. (This is surprisingly common issue in C/C++.)
50
+
- There is no default memory ordering, to avoid accidental (and costly) use of sequential consistency. (This is a surprisingly common issue in C/C++.)
51
51
52
52
- Operations such as compare/exchange prefer to keep input values cleanly separated from results. There are no `inout` parameters.
53
53
@@ -56,15 +56,15 @@ The primary focus is to provide systems programmers access to atomic operations
56
56
To use `Atomics` in your own project, you need to set it up as a package dependency:
.upToNextMajor(from: "1.1.0") // or `.upToNextMinor
67
+
.upToNextMajor(from: "1.2.0") // or `.upToNextMinor
68
68
)
69
69
],
70
70
targets: [
@@ -78,20 +78,76 @@ let package = Package(
78
78
)
79
79
```
80
80
81
+
## Compatibility
82
+
83
+
### Swift Releases
84
+
85
+
The atomics implementation is inherently far more tightly coupled to the compiler than usual, so tagged versions of this package typically only support a narrow range of Swift releases:
86
+
87
+
swift-atomics | Supported Swift Versions
88
+
--------------------|-------------------------
89
+
`1.0.x` | 5.3, 5.4, 5.5
90
+
`1.1.x` | 5.6, 5.7, 5.8
91
+
`1.2.x` | 5.7, 5.8, 5.9
92
+
`main` | 5.8, 5.9, unreleased snapshots of 5.10 and trunk
93
+
94
+
Note that the `main` branch is not a tagged release, so its contents are inherently unstable. Because of this, we do not recommended using it in production. (For example, its set of supported Swift releases is subject to change without notice.)
95
+
96
+
### Source Stability
97
+
98
+
The Swift Atomics package is source stable. The version numbers follow [Semantic Versioning][semver] -- source breaking changes to public API can only land in a new major version.
99
+
100
+
[semver]: https://semver.org
101
+
102
+
The public API of current versions of the `swift-atomics` package consists of non-underscored declarations that are marked `public` in the `Atomics` module.
103
+
104
+
By "underscored declarations" we mean declarations that have a leading underscore anywhere in their fully qualified name. For instance, here are some names that wouldn't be considered part of the public API, even if they were technically marked public:
Interfaces that aren't part of the public API may continue to change in any release, including patch releases.
112
+
113
+
Note that contents of the `_AtomicsShims` module explicitly aren't public API. (As implied by its underscored module name.) The definitions therein may therefore change at whim, and the entire module may be removed in any new release -- do not import this module directly. We also don't make any source compatibility promises about the contents of the `Utilities`, `Tests`, `Xcode` and `cmake` subdirectories.
114
+
115
+
If you have a use case that requires using underscored APIs, please [submit a Feature Request][enhancement] describing it! We'd like the public interface to be as useful as possible -- although preferably without compromising safety or limiting future evolution.
116
+
117
+
Future minor versions of the package may introduce changes to these rules as needed.
118
+
119
+
We'd like this package to quickly embrace Swift language and toolchain improvements that are relevant to its mandate. Accordingly, from time to time, new versions of this package will require clients to upgrade to a more recent Swift toolchain release. (This allows the package to make use of new language/stdlib features, build on compiler bug fixes, and adopt new package manager functionality as soon as they are available.)
120
+
121
+
Requiring a new Swift release will only require a minor version bump.
122
+
123
+
81
124
## Features
82
125
83
-
The package implements atomic operations for the following Swift constructs, all of which conform to the public `AtomicValue` protocol:
126
+
For a detailed overview of the interfaces offered by this package, please see [our API documentation][APIDocs].
The package implements atomic operations for the following Swift constructs, all of which conform to the public [`AtomicValue` protocol][AtomicValue]:
84
140
85
141
- Standard signed integer types (`Int`, `Int64`, `Int32`, `Int16`, `Int8`)
86
142
- Standard unsigned integer types (`UInt`, `UInt64`, `UInt32`, `UInt16`, `UInt8`)
87
143
- Booleans (`Bool`)
88
144
- Standard pointer types (`UnsafeRawPointer`, `UnsafeMutableRawPointer`, `UnsafePointer<T>`, `UnsafeMutablePointer<T>`), along with their optional-wrapped forms (such as `Optional<UnsafePointer<T>>`)
- A special `DoubleWord` type that consists of two `UInt` values, `first` and `second`, providing double-wide atomic primitives
146
+
- A special [`DoubleWord` type][DoubleWord] that consists of two `UInt` values, `first` and `second`, providing double-wide atomic primitives
91
147
- Any `RawRepresentable` type whose `RawValue` is in turn an atomic type (such as simple custom enum types)
92
-
- Strong references to class instances that opted into atomic use (by conforming to the `AtomicReference` protocol)
148
+
- Strong references to class instances that opted into atomic use (by conforming to the [`AtomicReference` protocol][AtomicReference])
93
149
94
-
Of particular note is full support for atomic strong references. This provides a convenient memory reclamation solution for concurrent data structures that fits perfectly with Swift's reference counting memory management model. (Atomic strong references are implemented in terms of `DoubleWord` operations.) However, accessing an atomic strong reference is (relatively) expensive, so we also provide a separate set of efficient constructs (`ManagedAtomicLazyReference` and `UnsafeAtomicLazyReference`) for the common case of a lazily initialized (but otherwise constant) atomic strong reference.
150
+
Of particular note is full support for atomic strong references. This provides a convenient memory reclamation solution for concurrent data structures that fits perfectly with Swift's reference counting memory management model. (Atomic strong references are implemented in terms of `DoubleWord` operations.) However, accessing an atomic strong reference is (relatively) expensive, so we also provide a separate set of efficient constructs ([`ManagedAtomicLazyReference`][ManagedAtomicLazyReference] and [`UnsafeAtomicLazyReference`][UnsafeAtomicLazyReference]) for the common case of a lazily initialized (but otherwise constant) atomic strong reference.
95
151
96
152
### Lock-Free vs Wait-Free Operations
97
153
@@ -107,12 +163,12 @@ Atomic access is implemented in terms of dedicated atomic storage representation
While the underlying pointer-based atomic operations are exposed as static methods on the corresponding `AtomicStorage` types, we strongly recommend the use of higher-level atomic wrappers to manage the details of preparing/disposing atomic storage. This version of the library provides two wrapper types:
166
+
While the underlying pointer-based atomic operations are exposed as static methods on the corresponding [`AtomicStorage`][AtomicStorage] types, we strongly recommend the use of higher-level atomic wrappers to manage the details of preparing/disposing atomic storage. This version of the library provides two wrapper types:
111
167
112
-
- an easy to use, memory-safe `ManagedAtomic<T>` generic class and
113
-
- a less convenient, but more flexible `UnsafeAtomic<T>` generic struct.
168
+
- an easy to use, memory-safe [`ManagedAtomic<T>`][ManagedAtomic] generic class and
169
+
- a less convenient, but more flexible [`UnsafeAtomic<T>`][UnsafeAtomic] generic struct.
114
170
115
-
Both constructs provide the following operations on all `AtomicValue` types:
171
+
Both constructs provide the following operations on all [`AtomicValue`][AtomicValue] types:
116
172
117
173
```swift
118
174
funcload(ordering: AtomicLoadOrdering) ->Value
@@ -146,7 +202,7 @@ func weakCompareExchange(
146
202
) -> (exchanged: Bool, original: Value)
147
203
```
148
204
149
-
Integer types come with additional atomic operations for incrementing or decrementing values and bitwise logical operations.
205
+
[Integer types][AtomicInteger] come with additional atomic operations for incrementing or decrementing values and bitwise logical operations.
150
206
151
207
```swift
152
208
funcloadThenWrappingIncrement(
@@ -247,34 +303,7 @@ func logicalXorThenLoad(
247
303
248
304
For an introduction to the APIs provided by this package, for now please see the [first version of SE-0282][SE-0282r0].
249
305
250
-
The current version of the `Atomics` module does not implement APIs for tagged atomics (see [issue #1](https://github.com/apple/swift-atomics/issues/1)), although it does expose a `DoubleWord` type that can be used to implement them. (Atomic strong references are already implemented in terms of `DoubleWord`, although in their current form they do not expose any user-customizable bits.)
251
-
252
-
## Source Stability
253
-
254
-
The Swift Atomics package is source stable. The version numbers follow [Semantic Versioning][semver] -- source breaking changes to public API can only land in a new major version.
255
-
256
-
[semver]: https://semver.org
257
-
258
-
The public API of version 1.1 of the `swift-atomics` package consists of non-underscored declarations that are marked `public` in the `Atomics` module.
259
-
260
-
By "underscored declarations" we mean declarations that have a leading underscore anywhere in their fully qualified name. For instance, here are some names that wouldn't be considered part of the public API, even if they were technically marked public:
Interfaces that aren't part of the public API may continue to change in any release, including patch releases.
268
-
269
-
Note that contents of the `_AtomicsShims` module explicitly aren't public API. (As implied by its underscored module name.) The definitions therein may therefore change at whim, and the entire module may be removed in any new release -- do not import this module directly. We also don't make any source compatibility promises about the contents of the `Utilities`, `Tests`, `Xcode` and `cmake` subdirectories.
270
-
271
-
If you have a use case that requires using underscored APIs, please [submit a Feature Request][enhancement] describing it! We'd like the public interface to be as useful as possible -- although preferably without compromising safety or limiting future evolution.
272
-
273
-
Future minor versions of the package may introduce changes to these rules as needed.
274
-
275
-
We'd like this package to quickly embrace Swift language and toolchain improvements that are relevant to its mandate. Accordingly, from time to time, new versions of this package will require clients to upgrade to a more recent Swift toolchain release. (This allows the package to make use of new language/stdlib features, build on compiler bug fixes, and adopt new package manager functionality as soon as they are available.)
276
-
277
-
Requiring a new Swift release will only require a minor version bump.
306
+
The current version of the `Atomics` module does not implement APIs for tagged atomics (see [issue #1](https://github.com/apple/swift-atomics/issues/1)), although it does expose a [`DoubleWord`][DoubleWord] type that can be used to implement them. (Atomic strong references are already implemented in terms of [`DoubleWord`][DoubleWord], although in their current form they do not expose any user-customizable bits.)
0 commit comments