Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Thread Sanitizer warnings #29

Open
jessegrosjean opened this issue Jun 22, 2021 · 0 comments
Open

Thread Sanitizer warnings #29

jessegrosjean opened this issue Jun 22, 2021 · 0 comments

Comments

@jessegrosjean
Copy link

I get Swift access race in Squid.Locked.lock() -> () at 0x7b080002f4e0 when running Squid under Xcode thread sanitizer. My understanding is there's not currently an actual issue in the threading code due to the way that Swift is generating code, but the thread analyzer can't be sure, so generates the warning.

I think to fix warning you can replace:

internal class Locked<Value> {
    private var _lock = os_unfair_lock()
    ...

with:

internal class Locked<Value> {
    private var _lock: UnsafeMutablePointer<os_unfair_lock>

    init(_ value: Value) {
        _lock = UnsafeMutablePointer<os_unfair_lock>.allocate(capacity: 1)
        _lock.initialize(to: os_unfair_lock())
        self._value = value
    }

I found this solution and an explanation here:

http://www.russbishop.net/the-law

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant