Fix Text Node Thread Sanitizer Warning #830
Merged
+13
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I made this before I saw that #819 exists, and while I think @hebertialmeida's solution may possibly be faster (though it could lead to thread explosion), I think this solution is more precise.
The race condition is in the C++ struct
ASTextKitAttributes
itself. Since there is no synchronization around the contents of that struct, the sanitizer is correctly warning us.This has led me down a heck of a rabbit-hole with memory safety. In lieu of a more general fix for the problem of creating very fast, but flexible and thread-safe C++ structures that interoperate well with Objective-C, this fix solves the thread sanitizer warnings in an appropriate way, by protecting access to that structure, at least in the
hash
andisEqual
methods, which seems sufficient since the class is specifically termed aKey
.Note that it's not sufficient to make the Objective-C property accessor atomic, since that seems only to protect the pointer. I don't know much about how synthesized atomic accessors treat c++ objects, but I wouldn't be surprised if they're not actually atomic.