Is this concurrency warning correct?

In a case like this where a closure captures a mutable local variable that variable is specifically not allocated on the stack and instead lives in a heap-allocated box for storing the capture context. E.g.:

func makeCounter() -> () -> Int {
    var x = 0
    return {
        x += 1
        return x
    }
}

let counter = makeCounter()
print(counter()) // 1
print(counter()) // 2
10 Likes