diff options
author | Abseil Team <absl-team@google.com> | 2021-10-06 17:55:30 -0700 |
---|---|---|
committer | rogeeff <rogeeff@google.com> | 2021-10-07 00:46:55 -0400 |
commit | a59b4daa07a14326d2ceb28cc6d0e079feea3338 (patch) | |
tree | dfde1cad62864dffeafd161aba4960ce0bf8aa99 /absl/synchronization | |
parent | ae0f4c266095c9003786cd571bc1fb72544104a1 (diff) |
Export of internal Abseil changes
--
17141711ee419daa597a9f31e73721f80143e55a by Gennadiy Rozental <rogeeff@google.com>:
Import of CCTZ from GitHub.
PiperOrigin-RevId: 401384949
--
ac48584a7b16e8a12e26d49deb6cddec584a20b5 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 401337785
--
8a51bb7c962845e0707240c5ba12c1b80f6fbbe9 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 401047691
--
8e18024510869247f3c04c7807c93709eca2322a by Chris Kennelly <ckennelly@google.com>:
Note that SpinLock does not guarantee priorities for wakeups.
PiperOrigin-RevId: 400999238
--
75bc09b5f95fbb74b74d14c370bfb80011e8fb7f by Derek Mauro <dmauro@google.com>:
Add visibility restrictions to some internal targets
PiperOrigin-RevId: 400718253
--
1de5061016bc42cd7be009c9725ed2343ce12e3d by Abseil Team <absl-team@google.com>:
Make it clear that operator<< can also be used in place of ToString when logging absl::Status.
PiperOrigin-RevId: 400248269
--
cda15d9dc6e5cd569de7e5e73f409b72a3caed51 by Abseil Team <absl-team@google.com>:
Minor cleanup
PiperOrigin-RevId: 400087535
--
b001375ec47da3a0434be9ca9a45c0df510e7dda by Abseil Team <absl-team@google.com>:
Move periodic_sampler from base/internal to profiling/internal
PiperOrigin-RevId: 400038533
--
e7e02e686abc3900e723080849a3607d190ef57f by Abseil Team <absl-team@google.com>:
Move exponential_biased from base/internal to profiling/internal
PiperOrigin-RevId: 400020329
GitOrigin-RevId: 17141711ee419daa597a9f31e73721f80143e55a
Change-Id: I10924df7e1cc198447813dbe97a374a5cef66b49
Diffstat (limited to 'absl/synchronization')
-rw-r--r-- | absl/synchronization/mutex_test.cc | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/absl/synchronization/mutex_test.cc b/absl/synchronization/mutex_test.cc index f8fbf948..4f403176 100644 --- a/absl/synchronization/mutex_test.cc +++ b/absl/synchronization/mutex_test.cc @@ -26,6 +26,7 @@ #include <random> #include <string> #include <thread> // NOLINT(build/c++11) +#include <type_traits> #include <vector> #include "gtest/gtest.h" @@ -870,33 +871,6 @@ TEST(Mutex, LockedMutexDestructionBug) ABSL_NO_THREAD_SAFETY_ANALYSIS { } } -// -------------------------------------------------------- -// Test for bug with pattern of readers using a condvar. The bug was that if a -// reader went to sleep on a condition variable while one or more other readers -// held the lock, but there were no waiters, the reader count (held in the -// mutex word) would be lost. (This is because Enqueue() had at one time -// always placed the thread on the Mutex queue. Later (CL 4075610), to -// tolerate re-entry into Mutex from a Condition predicate, Enqueue() was -// changed so that it could also place a thread on a condition-variable. This -// introduced the case where Enqueue() returned with an empty queue, and this -// case was handled incorrectly in one place.) - -static void ReaderForReaderOnCondVar(absl::Mutex *mu, absl::CondVar *cv, - int *running) { - std::random_device dev; - std::mt19937 gen(dev()); - std::uniform_int_distribution<int> random_millis(0, 15); - mu->ReaderLock(); - while (*running == 3) { - absl::SleepFor(absl::Milliseconds(random_millis(gen))); - cv->WaitWithTimeout(mu, absl::Milliseconds(random_millis(gen))); - } - mu->ReaderUnlock(); - mu->Lock(); - (*running)--; - mu->Unlock(); -} - struct True { template <class... Args> bool operator()(Args...) const { @@ -945,6 +919,33 @@ TEST(Mutex, FunctorCondition) { } } +// -------------------------------------------------------- +// Test for bug with pattern of readers using a condvar. The bug was that if a +// reader went to sleep on a condition variable while one or more other readers +// held the lock, but there were no waiters, the reader count (held in the +// mutex word) would be lost. (This is because Enqueue() had at one time +// always placed the thread on the Mutex queue. Later (CL 4075610), to +// tolerate re-entry into Mutex from a Condition predicate, Enqueue() was +// changed so that it could also place a thread on a condition-variable. This +// introduced the case where Enqueue() returned with an empty queue, and this +// case was handled incorrectly in one place.) + +static void ReaderForReaderOnCondVar(absl::Mutex *mu, absl::CondVar *cv, + int *running) { + std::random_device dev; + std::mt19937 gen(dev()); + std::uniform_int_distribution<int> random_millis(0, 15); + mu->ReaderLock(); + while (*running == 3) { + absl::SleepFor(absl::Milliseconds(random_millis(gen))); + cv->WaitWithTimeout(mu, absl::Milliseconds(random_millis(gen))); + } + mu->ReaderUnlock(); + mu->Lock(); + (*running)--; + mu->Unlock(); +} + static bool IntIsZero(int *x) { return *x == 0; } // Test for reader waiting condition variable when there are other readers |