That is not a real pointer. That is not valid for a long-lasting value such as a lock.
What you need in order to use a lock (or any construct that relies on the processor's atomic instructions) is to allocate on the heap, using UnsafeMutablePointer.allocate()
. That will get you a pointer that you can rely on. You can wrap that allocated pointer in a (final) class for convenience (and deal with cleanup/deallocation). There are many correct implementations like that out there.