Multithreaded OperationIn multithreaded programs, it is necessary to synchronize shared objects, to avoid inconsistencies due to scheduling in the middle of an (in/de)crement. This can be done by adding a mutex to each object, and locking it before doing the actual change of counter. Implementation of this is OS specific. OverheadThere are 2 kinds of overhead when using this scheme:
Usually, when correctness is required, this is a small price to pay. Pros-ConsDrawbacks: This scheme cannot be used in data structures where pointer circles are formed (e.g. doubly linked lists). For tree like structures (trees, vectors, singly linked lists) it can be safely used. Most game data is stored in tree-like structures so it is useful for games. Advantages:
|