<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Synchronization/atomicMemoryFence(ordering:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Synchronization"
    ],
    "preciseIdentifier" : "s:15Synchronization17atomicMemoryFence8orderingyAA20AtomicUpdateOrderingV_tF"
  },
  "title" : "atomicMemoryFence(ordering:)"
}
-->

# atomicMemoryFence(ordering:)

Establishes a memory ordering without associating it with a
particular atomic operation.

```
func atomicMemoryFence(ordering: AtomicUpdateOrdering)
```

## Discussion

- A relaxed fence has no effect.
- An acquiring fence ties to any preceding atomic operation that
  reads a value, and synchronizes with any releasing operation whose
  value was read.
- A releasing fence ties to any subsequent atomic operation that
  modifies a value, and synchronizes with any acquiring operation
  that reads the result.
- An acquiring and releasing fence is a combination of an
  acquiring and a releasing fence.
- A sequentially consistent fence behaves like an acquiring and
  releasing fence, and ensures that the fence itself is part of
  the single, total ordering for all sequentially consistent
  operations.

This operation corresponds to `std::atomic_thread_fence` in C++.

Be aware that Thread Sanitizer does not support fences and may report
false-positive races for data protected by a fence.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)