     init(starter: @escaping Starter) {
         self.starter = starter
 
-        self._isExecuting = UnsafeMutablePointer<Int32>.allocate(capacity: 1)
-        self._isExecuting.initialize(to: 0)
-
-        self._isFinished = UnsafeMutablePointer<Int32>.allocate(capacity: 1)
-        self._isFinished.initialize(to: 0)
-
-        self.isFinishCalled = UnsafeMutablePointer<Int32>.allocate(capacity: 1)
-        self.isFinishCalled.initialize(to: 0)
+        self.lock = .allocate(capacity: 1)
+        self.lock.initialize(to: os_unfair_lock())
 
         #if TRACK_ALLOCATIONS
         Allocations.increment("Operation")

import Foundation

final class Operation: Foundation.Operation {
    private let _isExecuting: UnsafeMutablePointer<Int32>
    private let _isFinished: UnsafeMutablePointer<Int32>
    private let isFinishCalled: UnsafeMutablePointer<Int32>

    override var isExecuting: Bool {
        get { _isExecuting.pointee == 1 }
        set {
            guard OSAtomicCompareAndSwap32Barrier(newValue ? 0 : 1, newValue ? 1 : 0, _isExecuting) else {
                return assertionFailure("Invalid state, operation is already (not) executing")
            }
            willChangeValue(forKey: "isExecuting")
            didChangeValue(forKey: "isExecuting")
        }
    }
    override var isFinished: Bool {
        get { _isFinished.pointee == 1 }
        set {
            guard OSAtomicCompareAndSwap32Barrier(newValue ? 0 : 1, newValue ? 1 : 0, _isFinished) else {
                return assertionFailure("Invalid state, operation is already finished")
            }
            willChangeValue(forKey: "isFinished")
            didChangeValue(forKey: "isFinished")
        }

    }

    private func _finish() {
        os_unfair_lock_lock(lock)
        if isFinishCalled {
            os_unfair_lock_unlock(lock)
            return
        }
        isFinishCalled = true
        os_unfair_lock_unlock(lock)

        isExecuting = false
        isFinished = true
    }
}

