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
+11-10Lines changed: 11 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,38 +24,39 @@ The integer types have the following methods:
24
24
`AtomicBool` has the following methods:
25
25
-`load`, `store`, `swap`, `CAS`, `and`, `or`, and `xor`.
26
26
27
-
The memory order (from `<stdatomic.h>`) can be set by using the `order` parameter on each method; the default is `.relaxed` for the integer types (it is sufficient for counter operations, the most common application,) and `.sequential` for pointer types.
27
+
The memory order (from `<stdatomic.h>`) can be set by using the `order` parameter on each method; the default is `.relaxed` for the integer types (it is sufficient for counter operations, the most common application,) and `.sequential` for pointer types. Note that `memory_order_consume` has no equivalent in this module, as (as far as I can tell) clang silently upgrades that to `memory_order_acquire`, making it impossible (at the moment) to test whether an algorithm can properly use `memory_order_consume`. This also means that nothing is lost by its absence.
28
28
29
-
The integer types also have a `value` property, as a convenient way to perform a `.relaxed` load. The pointer types have a `pointer` property for the same purpose.
29
+
The integer types also have a `value` property, as a convenient way to perform a `.relaxed` load.
30
+
The pointer types have a `pointer` property for the same purpose.
30
31
31
32
### Module CAtomics
32
33
33
-
The second module is `CAtomics`, which provides atomics to Swift using a C-style interface. `SwiftAtomics` is built on top of `CAtomics`. The types implemented in `CAtomics` are the same as in `SwiftAtomics`, minus the types which use generics features.
34
-
Fuctions defined in `CAtomics` are prefixed with `CAtomics`; they are `Load`, `Store`, `Exchange`, and `CompareAndExchange` for all types. The integer types add `Add`, `Subtract`, `BitwiseAnd`, `BitWiseOr`, and `BitWiseXor`; `AtomicBool` adds `And`, `Or`, and `Xor`.
34
+
The second module is `CAtomics`, which provides atomics to Swift using a C-style interface. `SwiftAtomics` is built on top of `CAtomics`. The types implemented in `CAtomics` are the same as in `SwiftAtomics`, minus the types which require swift's generic features.
35
+
Functions defined in `CAtomics` are prefixed with `CAtomics`; they are `Load`, `Store`, `Exchange`, and `CompareAndExchange` for all types. The integer types add `Add`, `Subtract`, `BitwiseAnd`, `BitWiseOr`, and `BitWiseXor`; `AtomicBool` adds `And`, `Or`, and `Xor`.
35
36
36
37
#### Notes on atomics and the law-of-exclusivity:
37
38
38
-
My experimentation has shown that these types are compatible with Swift 5's run-time exclusivity checking when used as members of class instances, but present difficulties when the thread sanitizer is enabled.
39
+
My experimentation has shown that the types defined in `SwiftAtomics` are compatible with Swift 5's run-time exclusivity checking when used as members of class instances, but present difficulties when the thread sanitizer is enabled.
39
40
40
41
Atomic types are useful as synchronization points between threads, and therefore have an interesting relationship with Swift's exclusivity checking. Firstly, they should be used as members of reference types, or directly captured by closures. They are `struct` types, so as to be not incur additional memory allocation, but that feature means that if you use the thread sanitizer, it will warn about them.
41
42
42
-
In order to use atomics in a way that is acceptable to the thread sanitizer; you must allocate memory for atomic variables on the heap using `UnsafeMutablePointer`, and then pass that pointer to the `CAtomics`functions as needed. Unfortunately I have not found a way to use the swift-style wrappers in a way that doesn't trigger the thread sanitizer.
43
+
In order to use atomics in a way that is acceptable to the thread sanitizer, one must have allocated memory for atomic variables on the heap using `UnsafeMutablePointer`. Then, pass that pointer to the functions defined in the `CAtomics`module, as needed. I haven't found a way to use the swift-style wrappers in a way that doesn't trigger the thread sanitizer.
0 commit comments