// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2016 Dmitry Vyukov <dvyukov@google.com> // Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// Visual studio doesn't implement a rand_r() function since its // implementation of rand() is already thread safe int rand_reentrant(unsignedint* s) { #ifdef EIGEN_COMP_MSVC_STRICT
EIGEN_UNUSED_VARIABLE(s); return rand(); #else return rand_r(s); #endif
}
bool Push() { int val = val_.load(std::memory_order_relaxed); for (;;) {
VERIFY_GE(val, 0);
VERIFY_LE(val, kQueueSize); if (val == kQueueSize) returnfalse; if (val_.compare_exchange_weak(val, val + 1, std::memory_order_relaxed)) returntrue;
}
}
bool Pop() { int val = val_.load(std::memory_order_relaxed); for (;;) {
VERIFY_GE(val, 0);
VERIFY_LE(val, kQueueSize); if (val == 0) returnfalse; if (val_.compare_exchange_weak(val, val - 1, std::memory_order_relaxed)) returntrue;
}
}
// A number of producers send messages to a set of consumers using a set of // fake queues. Ensure that it does not crash, consumers don't deadlock and // number of blocked and unblocked threads match. staticvoid test_stress_eventcount()
{ constint kThreads = std::thread::hardware_concurrency(); staticconstint kEvents = 1 << 16; staticconstint kQueues = 10;
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 ist noch experimentell.