Let's say, there is a variable that I want to make thread safe. One of the most common ways to do this:

```
var value: A {
    get { return queue.sync { self._value } }
    set { queue.sync { self._value = newValue } }
}

```

However, [this property is not completely thread safe](https://www.objc.io/blog/2018/12/18/atomic-variables/) if we change the value as in the example below:

```
Class.value += 1

```

So my question is: Using NSLock on the same principle **is also not completely thread safe?**

```
var value: A {
    get { 
       lock.lock()
       defer { lock.unlock() }
       return self._value
    }
    set { 
       lock.lock()
       defer { lock.unlock() }
       self._value = newValue
    }
}

```