# \#mutex

**URL:** https://forums.swift.org/tag/mutex/630.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [How do we make a class with mutable data Sendable?](https://forums.swift.org/t/how-do-we-make-a-class-with-mutable-data-sendable/88229)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 9\
**Last updated:** [July 13, 2026, 10:22pm UTC](https://forums.swift.org/t/how-do-we-make-a-class-with-mutable-data-sendable/88229 "2026-07-13T22:22:29Z")

</div>

Since other explanations seem clear as mud, I came up with an implementation based off AI slop. I don't know if the file is visible to others. It's a class-based collection that wraps a value-type collection, and will b…

---

## [Should Swift 6 prevent sharing a non-Sendable value via Mutex?](https://forums.swift.org/t/should-swift-6-prevent-sharing-a-non-sendable-value-via-mutex/86523)

<div class="topic-metadata">

**Author:** [@bjhomer](https://forums.swift.org/u/bjhomer)\
**Replies:** 6\
**Last updated:** [May 6, 2026, 6:10pm UTC](https://forums.swift.org/t/should-swift-6-prevent-sharing-a-non-sendable-value-via-mutex/86523 "2026-05-06T18:10:23Z")

</div>

The following code produces no warnings or errors under Swift 6, even though NonSendable is being effectively shared across concurrency domains. Is this expected? import Synchronization class NonSendable { var name…

---

## [Why can't I store this \`sending\` parameter in my mutex?](https://forums.swift.org/t/why-cant-i-store-this-sending-parameter-in-my-mutex/85449)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 15\
**Last updated:** [April 3, 2026, 2:52am UTC](https://forums.swift.org/t/why-cant-i-store-this-sending-parameter-in-my-mutex/85449 "2026-04-03T02:52:06Z")

</div>

Can anyone shed some deeper light on why the following code doesn't compile? import Foundation import Synchronization final class A { let state = Mutex(State()) struct State { var callbacks: \[UUID:…

---

## [SE-0512: Document that Mutex.withLockIfAvailable(\_:) cannot spuriously fail](https://forums.swift.org/t/se-0512-document-that-mutex-withlockifavailable-cannot-spuriously-fail/84789)

<div class="topic-metadata">

**Author:** [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Replies:** 23\
**Last updated:** [March 9, 2026, 6:17pm UTC](https://forums.swift.org/t/se-0512-document-that-mutex-withlockifavailable-cannot-spuriously-fail/84789 "2026-03-09T18:17:06Z")

</div>

Hello, Swift community. The review of SE-0512: Document that Mutex.withLockIfAvailable(\_:) cannot spuriously fail begins now and runs through March 2nd, 2026. Reviews are an important part of the Swift evolution proces…

---

## [\[Accepted\] SE-0512: Document that Mutex.withLockIfAvailable(\_:) cannot spuriously fail](https://forums.swift.org/t/accepted-se-0512-document-that-mutex-withlockifavailable-cannot-spuriously-fail/85225)

<div class="topic-metadata">

**Author:** [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Replies:** 0\
**Last updated:** [March 9, 2026, 6:15pm UTC](https://forums.swift.org/t/accepted-se-0512-document-that-mutex-withlockifavailable-cannot-spuriously-fail/85225 "2026-03-09T18:15:53Z")

</div>

Hello, Swift community. The review of SE-0512: Document that Mutex.withLockIfAvailable(\_:) cannot spuriously fail ran from February 17th through March 2nd, 2026. There was a spirited technical discussion in the review …

---

## [Got crashes while transitioning from NSLock to Mutex](https://forums.swift.org/t/got-crashes-while-transitioning-from-nslock-to-mutex/84696)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 1\
**Last updated:** [February 12, 2026, 8:09pm UTC](https://forums.swift.org/t/got-crashes-while-transitioning-from-nslock-to-mutex/84696 "2026-02-12T20:09:21Z")

</div>

Granted, the code is modified AI slop. I asked this on another forum, and they directed me here. This is a successor to: https://developer.apple.com/forums/thread/814231 I went into a slightly different direction. I…

---

## [Deadlock With \`AsyncStream\`s and a Single \`Mutex\`](https://forums.swift.org/t/deadlock-with-asyncstream-s-and-a-single-mutex/84584)

<div class="topic-metadata">

**Author:** [@FiggChristian](https://forums.swift.org/u/FiggChristian)\
**Replies:** 8\
**Last updated:** [February 9, 2026, 1:53pm UTC](https://forums.swift.org/t/deadlock-with-asyncstream-s-and-a-single-mutex/84584 "2026-02-09T13:53:37Z")

</div>

I’m encountering a deadlock with the following code (Swift 6.2.3), which is using a single Mutex, and feels like it should work since the acquires/releases are well-ordered. import Synchronization // Synchronous access…

---

## [Should we document the behavior of \`Mutex.withLockIfAvailable()\`?](https://forums.swift.org/t/should-we-document-the-behavior-of-mutex-withlockifavailable/83166)

<div class="topic-metadata">

**Author:** [@grynspan](https://forums.swift.org/u/grynspan)\
**Replies:** 9\
**Last updated:** [January 20, 2026, 11:40pm UTC](https://forums.swift.org/t/should-we-document-the-behavior-of-mutex-withlockifavailable/83166 "2026-01-20T23:40:18Z")

</div>

The documentation for Mutex.withLockIfAvailable() does not specify if it can spuriously fail to acquire the mutex. I'd like to get feedback from the community: should we make clear that it cannot fail in this fashion? T…

---

## [Why does \`Mutex\` let me send non-\`Sendable\` types?](https://forums.swift.org/t/why-does-mutex-let-me-send-non-sendable-types/83014)

<div class="topic-metadata">

**Author:** [@FiggChristian](https://forums.swift.org/u/FiggChristian)\
**Replies:** 4\
**Last updated:** [November 5, 2025, 6:14am UTC](https://forums.swift.org/t/why-does-mutex-let-me-send-non-sendable-types/83014 "2025-11-05T06:14:25Z")

</div>

Why does this code snippet work and allow me to access a non-Sendable type outside of where it should be accessible? import Synchronization final class NS { var value: Int = 0 init(\_ value: Int = 0) { self.value = va…

---

## [Combining @Observable and @Sendable](https://forums.swift.org/t/combining-observable-and-sendable/79229)

<div class="topic-metadata">

**Author:** [@cloudgazing](https://forums.swift.org/u/cloudgazing)\
**Replies:** 4\
**Last updated:** [April 14, 2025, 3:20pm UTC](https://forums.swift.org/t/combining-observable-and-sendable/79229 "2025-04-14T15:20:18Z")

</div>

Hi all, I'm working on an app which uses FFI (not sure if it's relevant, but it's Rust) and I'm struggling with updating my view models correctly and getting SwiftUI to reflect those changes. Right now, I'm using Unman…

---

## [Sending, inout sending, Mutex](https://forums.swift.org/t/sending-inout-sending-mutex/76373)

<div class="topic-metadata">

**Author:** [@KeithBauerANZ](https://forums.swift.org/u/KeithBauerANZ)\
**Replies:** 14\
**Last updated:** [April 3, 2025, 7:45am UTC](https://forums.swift.org/t/sending-inout-sending-mutex/76373 "2025-04-03T07:45:00Z")

</div>

So, I was looking at Swift 6's new Mutex type, and I saw that its withLock has a new Swift6-y signature. It has a few extra bits and bobs, but here's a simplified version: func withLock\<R\>( \_ body: (inout se…

---

## [What does the \`Result: ~Copyable\` constraint mean in the Mutex API (and in general)?](https://forums.swift.org/t/what-does-the-result-copyable-constraint-mean-in-the-mutex-api-and-in-general/74860)

<div class="topic-metadata">

**Author:** [@jamieQ](https://forums.swift.org/u/jamieQ)\
**Replies:** 4\
**Last updated:** [September 22, 2024, 8:13pm UTC](https://forums.swift.org/t/what-does-the-result-copyable-constraint-mean-in-the-mutex-api-and-in-general/74860 "2024-09-22T20:13:13Z")

</div>

currently, the Mutex type's locking method has the following signature: public borrowing func withLock\<Result: ~Copyable, E: Error\>( \_ body: (inout sending Value) throws(E) -\> sending Result ) throws(E) -\> sending Res…

---

## [Combing sending and Mutex in Swift 6](https://forums.swift.org/t/combing-sending-and-mutex-in-swift-6/74630)

<div class="topic-metadata">

**Author:** [@pnewell](https://forums.swift.org/u/pnewell)\
**Replies:** 5\
**Last updated:** [September 16, 2024, 3:14pm UTC](https://forums.swift.org/t/combing-sending-and-mutex-in-swift-6/74630 "2024-09-16T15:14:13Z")

</div>

I am trying to using the new sending parameter keyword together with Mutex to handle one Opaque pinter creating another but so far have not been able to get it working and am now wondering if I've misunderstood how it is…

---

## [\[Pitch\] Synchronous Mutual Exclusion Lock](https://forums.swift.org/t/pitch-synchronous-mutual-exclusion-lock/69889)

<div class="topic-metadata">

**Author:** [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Replies:** 55\
**Last updated:** [February 20, 2024, 6:55pm UTC](https://forums.swift.org/t/pitch-synchronous-mutual-exclusion-lock/69889 "2024-02-20T18:55:05Z")

</div>

Hi all, I would like to propose a new type in the Synchronization module, Mutex. This type is a synchronous mutual exclusion lock, similar to things like OSAllocatedUnfairLock, NIOLock, etc. Please let me know what you t…

---

## [Thread sanitiser v mutex](https://forums.swift.org/t/thread-sanitiser-v-mutex/54515)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 2\
**Last updated:** [January 9, 2022, 6:18pm UTC](https://forums.swift.org/t/thread-sanitiser-v-mutex/54515 "2022-01-09T18:18:30Z")

</div>

I am getting thread sanitiser "Swift access race" on pthread\_mutex\_lock line. How do I use mutex properly in Swift? import Foundation class MiniTest { var mutex = pthread\_mutex\_t() init() { pthread…
