SE-0176 Enforce Exclusive Access to Memory 
 states that "Accesses to different stored properties of a struct or different 
elements of a tuple are allowed to overlap."

And indeed this compiles and runs as expected (Xcode 9 beta 4):

    // main.swift

    func foo()  {
        var tuple = (1, 2)
        swap(&tuple.0, &tuple.1)


However, if the tuple is a global variable, it crashes with a runtime exception:

    // main.swift

    var tuple = (1, 2)
    swap(&tuple.0, &tuple.1)

    Simultaneous accesses to 0x100401cb0, but modification requires exclusive 
    Previous access (a modification) started at tupleaccess`main + 76 
    Current access (a modification) started at:
    0    tupleaccess                        0x0000000100335b60 
swift_beginAccess + 605
    1    tupleaccess                        0x0000000100001580 main + 110
    2    libdyld.dylib                      0x00007fffa7284234 start + 1

Is there anything special with simultaneous access to members of a global 
tuple, or is this a bug?

Regards, Martin

swift-users mailing list

Reply via email to