// Note that the implementation here is in itself racy, but we pretend it does // not matter because we want this useful in release builds without having to // pay the cost of using atomics. A race hitting the race checker is likely to // cause access_count_ to diverge from zero and therefore cause the ThreadRef // comparison to fail, signaling a race, although it may not be in the exact // spot where a race *first* appeared in the code we're trying to protect. There // is also a chance that an actual race is missed, however the probability of // that has been considered small enough to be an acceptable trade off. bool RaceChecker::Acquire() const { const PlatformThreadRef current_thread = CurrentThreadRef(); // Set new accessing thread if this is a new use. const int current_access_count = access_count_;
access_count_ = access_count_ + 1;
if (current_access_count == 0)
accessing_thread_ = current_thread; // If this is being used concurrently this check will fail for the second // thread entering since it won't set the thread. Recursive use of checked // methods are OK since the accessing thread remains the same. const PlatformThreadRef accessing_thread = accessing_thread_; return IsThreadRefEqual(accessing_thread, current_thread);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.