Not all types in Nito.Weakness are threadsafe (e.g.,
are fully threadsafe.
- Multiple threads may attempt to retrieve
ObjectIds at the same time. This contention is mitigated within the
ObjectTracker by defining two tiers of concurrent lookups: the instance's
exact type and its hash code. This reduces multithreaded contention in this scenario to a much smaller scope: the
target objects must be of the same type and have the same hash code in order to cause contention.
- One thread may attempt to retrieve an
ObjectId and contend with the
GC detection thread if it is traversing the same part of the lookup tree.
- Multiple threads may
register actions for the same
ObjectId at the same time.
- One thread may
register an action for an
target is being garbage collected. In this case, a race condition "winner" is determined:
- If the user thread wins, then the target is kept alive until the action is registered. The target may then be garbage collected as normal, and the registered action will eventually be invoked by the
GC detection thread.
- If the garbage collector wins, then the action is not registered, and is invoked immediately.
- When an AppDomain begins unloading, no more
registered actions are invoked. This is a race condition that normally happens when an application exits.
Race conditions (handled by Nito.Weakness)