# Use of nonisolated(unsafe) and bridging headers

**URL:** <https://forums.swift.org/t/use-of-nonisolated-unsafe-and-bridging-headers/72543>\
**Category:** Using Swift\
**Created:** [June 17, 2024, 3:57pm UTC](https://forums.swift.org/t/use-of-nonisolated-unsafe-and-bridging-headers/72543 "2024-06-17T15:57:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![otrejo-soria](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/otrejo-soria/32/35974_2.png) [@otrejo-soria](https://forums.swift.org/u/otrejo-soria)\
**Post date:** [June 17, 2024, 3:57pm UTC](https://forums.swift.org/t/use-of-nonisolated-unsafe-and-bridging-headers/72543/1 "2024-06-17T15:57:29Z")

</div>

I was reading the following threads [SE-0412: Strict concurrency for global variables](https://forums.swift.org/t/se-0412-strict-concurrency-for-global-variables/68352) and [Concurrency-safe global variables to prevent data races - SwiftLee](https://www.avanderlee.com/concurrency/concurrency-safe-global-variables-to-prevent-data-races/), but now I stumble upon a similar situation where the swift compiler is still throwing the error:

```swift
error: reference to var 'my_c_variable' is not concurrency-safe because it involves shared mutable state

```

I have my\_c\_variable located in c source file and it's using a bridge header file in order to be compiled as part of my swift sources.

The problem is that I cannot use the nonisolated(unsafe) in the c source file because it's not valid.

This the actual error I get:

```swift
error: reference to var 'my_c_variable' is not concurrency-safe because it involves shared mutable state
        my_c_variable= 0xDEFEADED
        ^
__ObjC.my_c_variable:1:12: note: var declared here
public var my_c_variable: UInt32

```

Any ideas if there is a way to workaround this? or if if there is native identifier in c equivalent to nonisolated(unsafe)?

---

<div class="post-metadata">

**Author:** ![eskimo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/eskimo/32/13558_2.png) [@eskimo](https://forums.swift.org/u/eskimo)\
**Post date:** [June 18, 2024, 9:00am UTC](https://forums.swift.org/t/use-of-nonisolated-unsafe-and-bridging-headers/72543/2 "2024-06-18T09:00:26Z")

</div>

> The problem is that I cannot use the nonisolated(unsafe) in  
> the c source file because it's not valid.

The following works for me:

```c
extern int my_c_variable __attribute__ ((swift_attr("nonisolated(unsafe)")));

```

I was using the Swift 6 in Xcode 16.0b1.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

---

<div class="post-metadata">

**Author:** ![otrejo-soria](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/otrejo-soria/32/35974_2.png) [@otrejo-soria](https://forums.swift.org/u/otrejo-soria)\
**Post date:** [June 18, 2024, 12:47pm UTC](https://forums.swift.org/t/use-of-nonisolated-unsafe-and-bridging-headers/72543/4 "2024-06-18T12:47:27Z")

</div>

Nice that worked. I completely forgot about **attribute**

I was working around it by re-declaring the variable in swift code like so

```swift
nonisolated(unsafe) public var my_c_variable: UInt32!

```

but wasn't sure if that was the correct way.

I appreciate the help. 😃
