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

Thread Sanitizer warnings #29

@jessegrosjean

Description

@jessegrosjean

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions