     }
 
     public static func codepointsForName(_ name: String) -> [UnicodeScalar]? {
+        if !Thread.isMainThread {
+            multipointsSemaphore.wait()
+        }
         if let scalars = multipoints[name] {
+            if !Thread.isMainThread {
+                multipointsSemaphore.signal()
+            }
             return scalars
-        } else if let scalar = EscapeMode.extended.codepointForName(name) {
+        }
+        if !Thread.isMainThread {
+            multipointsSemaphore.signal()
+        }
+        
+        if let scalar = EscapeMode.extended.codepointForName(name) {
             return [scalar]
         }
         return nil

                entitiesByName.append(NamedCodepoint(scalar: UnicodeScalar(cp1)!, name: name))

                if (cp2 != empty) {
                    multipoints[name] = [UnicodeScalar(cp1)!, UnicodeScalar(cp2)!]
                }
            }
            // Entities should start in name order, but better safe than sorry...

    }

    private static var multipoints: [String: [UnicodeScalar]] = [:] // name -> multiple character references
    private static var multipointsSemaphore = DispatchSemaphore(value: 1)

    /**
     * Check if the input is a known named entity
