Implementation of reference counting methods in TInterfacedObject
is thread safe as reference count is incremented and decremented atomically.
When reference count of object instance reaches zero in _Release
method, that means there is no longer any other strong reference to that object and destroying the object will be thread-safe.
Similarly when you look at _AddRef
method, when you already have a strong reference to an object, taking another strong reference from it will also be thread-safe.
However, that is not the whole story and there are other things that need to be taken in consideration when handling reference counted instances across multiple threads.
reference assignment is not thread-safe - you cannot have a variable and write to it from multiple threads in thread-safe manner without using additional access protection mechanisms that will ensure only single thread has access to that reference at a time, like locks.
taking strong reference from weak reference is not thread-safe - if thread only has a weak reference to some reference counted instance then you cannot assign that weak reference to a strong one in thread-safe manner