[Bug]: add serial dispatch queue for `storedCalls` to avoid data-race

Merged
AM
2y ago
+13-6

Accessing storedCalls from two different threads causes crash since Dictionary is not thread safe that introduces data-race. The serial queue prevents the access to the shared resource by two different threads by queuing the operation and invoking the functions one-by-one.

There is other option to avoid data-race using locks, and top of that, there are two types of locks that can be used here: NSLock and the other one is OSAllocatedUnfairLock, which is faster than the first one.