# \[UE 5.8.4\]\[Mac\] FRWLock asserts "pthread\_rwlock\_init failed with error: 16" when built over recycled heap memory

**URL:** <https://forums.unrealengine.com/t/ue-5-8-4-mac-frwlock-asserts-pthread-rwlock-init-failed-with-error-16-when-built-over-recycled-heap-memory/2876888>\
**Category:** Issues and Bug Reporting (Unreal Engine)\
**Tags:** unreal-engine\
**Created:** [December 4, 2026, 2:37am UTC](https://forums.unrealengine.com/t/ue-5-8-4-mac-frwlock-asserts-pthread-rwlock-init-failed-with-error-16-when-built-over-recycled-heap-memory/2876888 "2026-12-04T02:37:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dwight\_Everhart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dwight\_Everhart](https://forums.unrealengine.com/u/Dwight_Everhart)\
**Post date:** [December 4, 2026, 2:37am UTC](https://forums.unrealengine.com/t/ue-5-8-4-mac-frwlock-asserts-pthread-rwlock-init-failed-with-error-16-when-built-over-recycled-heap-memory/2876888/1 "2026-12-04T02:37:27Z")

</div>

### Summary

On macOS, `FPThreadsSharedMutex` (`FRWLock`) runs `pthread_rwlock_init` on its member without clearing it first. Apple’s `pthread_rwlock_init` reads the existing bytes. If they hold an initialized lock whose lock and unlock counts disagree, it returns `EBUSY` and the constructor’s `checkf` fires. Reused heap memory regularly holds such stale lock bytes, so a lock that is a member of a heap object occasionally lands on them. We hit it in Chaos (`TRigidParticles::SleepDataLock`, during `UWorld::CreatePhysicsScene`) and in Mass (`FMassArchetypeSharedFragmentValues`, during a TEDS command flush).

### What Type of Bug are you experiencing?

Foundation (C++ Tools, Profiling, & Pipeline)

### Steps to Reproduce

1. On a Mac, in any C++ project, run this (for example from an automation test):

```cpp
alignas(16) uint8 Bytes[sizeof(FRWLock)] = {};
pthread_rwlock_t* Stale = reinterpret_cast<pthread_rwlock_t*>(Bytes); // FRWLock's only member
pthread_rwlock_init(Stale, nullptr);
pthread_rwlock_wrlock(Stale); // leave the bytes of a lock that is in use
new (Bytes) FRWLock; // default-initialized, as a class member is

```

1. The `FRWLock` constructor asserts.

`new (Bytes) FRWLock()` with parentheses does not reproduce it, because value-initialization zeroes the bytes first.

### Expected Result

The lock initializes. The memory was never a lock of this object, so its old contents shouldn’t matter.

### Observed Result

`Assertion failed: Err == 0 [File:Runtime/Core/Public/HAL/PThreadsSharedMutex.h] [Line: 32] pthread_rwlock_init failed with error: 16`

### Affects Versions

5.8

### Platform(s)

Mac

### Additional Notes

- macOS reads the lock’s counts from a 16-byte-aligned slot inside the 200-byte `pthread_rwlock_t`, computed from the lock’s own address. So an unlocked lock that was moved 8 bytes off its 16-byte alignment is refused too.
- Stale lock bytes are common in freed memory. One run of our automation suite frees about 25,000 locks that were never destroyed, mostly old copies left when a container is reallocated.
- One engine source of refused ones: the constructor of Chaos’s `TAABBTree::FWorkSnapshot` leaves `AverageCenter`, `ScaledCenterVariance`, `NodeLevel`, `NewNodeIdx`, `BestBoundsCurIdx` and `SplitInfos[].WorkSnapshotIdx` uninitialized. An old signature survives in those fields while bounds are written over the words read as counts. An allocator probe caught 7 such `WorkPool` blocks freed in a single run.
- Rate: 1 in 413 full runs of our editor automation suite.
- Packaged Development builds don’t hit it, because `FMallocPoisonProxy` fills each new allocation. The editor and Shipping builds do. Windows (SRWLOCK) and Linux (glibc) never read the old bytes.
- Suggested fix: clear the mutex before initializing it in `FPThreadsSharedMutex`’s constructor, for example with `FMemory::Memzero(Mutex)`. Initializing `FWorkSnapshot`’s fields would also remove one source.
- Earlier report of the Mass/TEDS occurrence: [[UE 5.8.4][Editor][Mac] Crash: pthread rwlock init fails with EBUSY (16) copying Mass shared fragment values during a TEDS command flush](https://forums.unrealengine.com/t/ue-5-8-4-editor-mac-crash-pthread-rwlock-init-fails-with-ebusy-16-copying-mass-shared-fragment-values-during-a-teds-command-flush/2848700)
