# Race condition behaviors

**URL:** <https://forums.swift.org/t/race-condition-behaviors/54322>\
**Category:** Using Swift\
**Tags:** concurrency\
**Created:** [December 28, 2021, 7:28am UTC](https://forums.swift.org/t/race-condition-behaviors/54322 "2021-12-28T07:28:23Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Karl](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Karl](https://forums.swift.org/u/Karl)\
**Post date:** [January 3, 2022, 3:04pm UTC](https://forums.swift.org/t/race-condition-behaviors/54322/15 "2022-01-03T15:04:35Z")

</div>

> [@John\_McCall](#):
>
> For example, Swift might choose to "pack" two different `Bool` struct properties into the same byte of storage, and it does not have to use atomic sequences to update them. (Swift does not currently perform this optimization, but it's permitted because of the rules about data races on structs. It would not be permitted for class properties.)

Is it actually permitted? That would mean `MemoryLayout.offset(of:)` could return nil or not based on the whims of the optimiser, or the target platform.

Packing trivial struct fields in to unaligned storage is probably fine (each field would still have a byte offset), but packing multiple fields as a single byte would probably require some kind of opt-in attribute, wouldn’t it?

---

_[View the full topic](https://forums.swift.org/t/race-condition-behaviors/54322)._
