Commits

Guillaume Lessard committed 94a9c512b92
[runtime] thread safety for weak references It has been fairly easy to cause the runtime to crash on multithreaded read-read access to weak references (e.g. https://bugs.swift.org/browse/SR-192). Although weak references are value types, they can get elevated to the heap in multiple ways, such as when captured by a closure or when used as a property in a class object instance. In such cases, race conditions involving weak references could cause the runtime to perform to multiple decrement operations of the unowned reference count for a single increment; this eventually causes early deallocation, leading to use-after-free, modify-after-free and double-free errors. This commit changes the weak reference operations to use a spinlock rather than assuming thread-exclusive access, when appropriate. With this change, the crasher discussed in SR-192 no longer encounters crashes due to modify-after-free or double-free errors.