Skip to content

Commit

Permalink
[ASTextNode] Fix a deadlock that could occur when enabling experiment…
Browse files Browse the repository at this point in the history
…al ASTextNode2 via ASConfiguration (TextureGroup#903)

Because multiple threads can enter this allocWithZone: method around the same time, it is possible for one of them to setSuperclass first, and then the second thread would get stuck in an infinite loop. When climbing the inheritance heirarchy, ASTextNode2 would be encountered by this second thread, and it would continue until reaching c == Nil. Since there was no case to catch this, an infinite loop would result. Then the main thread can be deadlocked if a method like waitUntilAllUpdatesAreProcessed is called on ASCollectionView.
  • Loading branch information
appleguy authored and Adlai-Holler committed May 3, 2018
1 parent 64c9b38 commit 9de3336
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1324,8 +1324,9 @@ + (id)allocWithZone:(struct _NSZone *)zone
// We are descended from ASTextNode. We need to change the superclass for the
// ASTextNode subclass to ASTextNode2.
// Walk up the class hierarchy until we find ASTextNode.
// Note: This may be called on multiple threads simultaneously.
Class s;
for (Class c = self; c != [ASTextNode class]; c = s) {
for (Class c = self; c != Nil && c != [ASTextNode class]; c = s) {
s = class_getSuperclass(c);
if (s == [ASTextNode class]) {
#pragma clang diagnostic push
Expand Down

0 comments on commit 9de3336

Please sign in to comment.