2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/SharedMutex.h>
22 #include <boost/optional.hpp>
23 #include <folly/Benchmark.h>
24 #include <folly/MPMCQueue.h>
25 #include <folly/Random.h>
26 #include <folly/test/DeterministicSchedule.h>
27 #include <gflags/gflags.h>
28 #include <gtest/gtest.h>
30 #include <boost/thread/shared_mutex.hpp>
31 #include <folly/RWSpinLock.h>
33 using namespace folly;
34 using namespace folly::test;
36 using namespace chrono;
38 typedef DeterministicSchedule DSched;
39 typedef SharedMutexImpl<true, void, DeterministicAtomic, true>
40 DSharedMutexReadPriority;
41 typedef SharedMutexImpl<false, void, DeterministicAtomic, true>
42 DSharedMutexWritePriority;
44 COMMON_CONCURRENCY_SHARED_MUTEX_DECLARE_STATIC_STORAGE(
45 DSharedMutexReadPriority);
46 COMMON_CONCURRENCY_SHARED_MUTEX_DECLARE_STATIC_STORAGE(
47 DSharedMutexWritePriority);
49 template <typename Lock>
52 SharedMutexToken token1;
53 SharedMutexToken token2;
54 SharedMutexToken token3;
56 EXPECT_TRUE(lock.try_lock());
57 EXPECT_FALSE(lock.try_lock());
58 EXPECT_FALSE(lock.try_lock_shared(token1));
61 EXPECT_TRUE(lock.try_lock_shared(token1));
62 EXPECT_FALSE(lock.try_lock());
63 EXPECT_TRUE(lock.try_lock_shared(token2));
64 lock.lock_shared(token3);
65 lock.unlock_shared(token3);
66 lock.unlock_shared(token2);
67 lock.unlock_shared(token1);
72 lock.lock_shared(token1);
73 lock.lock_shared(token2);
74 lock.unlock_shared(token1);
75 lock.unlock_shared(token2);
78 lock.unlock_and_lock_shared(token1);
79 lock.lock_shared(token2);
80 lock.unlock_shared(token2);
81 lock.unlock_shared(token1);
84 TEST(SharedMutex, basic) {
85 runBasicTest<SharedMutexReadPriority>();
86 runBasicTest<SharedMutexWritePriority>();
89 template <typename Lock>
90 void runBasicHoldersTest() {
92 SharedMutexToken token;
95 typename Lock::WriteHolder holder(lock);
96 EXPECT_FALSE(lock.try_lock());
97 EXPECT_FALSE(lock.try_lock_shared(token));
99 typename Lock::WriteHolder holder2(std::move(holder));
100 typename Lock::WriteHolder holder3;
101 holder3 = std::move(holder2);
103 typename Lock::UpgradeHolder holder4(std::move(holder3));
104 typename Lock::WriteHolder holder5(std::move(holder4));
106 typename Lock::ReadHolder holder6(std::move(holder5));
108 EXPECT_FALSE(lock.try_lock());
109 EXPECT_TRUE(lock.try_lock_shared(token));
110 lock.unlock_shared(token);
114 typename Lock::WriteHolder holder(lock);
115 EXPECT_FALSE(lock.try_lock());
119 typename Lock::ReadHolder holder(lock);
120 typename Lock::ReadHolder holder2(lock);
121 typename Lock::UpgradeHolder holder3(lock);
125 typename Lock::UpgradeHolder holder(lock);
126 typename Lock::ReadHolder holder2(lock);
127 typename Lock::ReadHolder holder3(std::move(holder));
131 TEST(SharedMutex, basic_holders) {
132 runBasicHoldersTest<SharedMutexReadPriority>();
133 runBasicHoldersTest<SharedMutexWritePriority>();
136 template <typename Lock>
137 void runManyReadLocksTestWithTokens() {
140 vector<SharedMutexToken> tokens;
141 for (int i = 0; i < 1000; ++i) {
142 tokens.emplace_back();
143 EXPECT_TRUE(lock.try_lock_shared(tokens.back()));
145 for (auto& token : tokens) {
146 lock.unlock_shared(token);
148 EXPECT_TRUE(lock.try_lock());
152 TEST(SharedMutex, many_read_locks_with_tokens) {
153 runManyReadLocksTestWithTokens<SharedMutexReadPriority>();
154 runManyReadLocksTestWithTokens<SharedMutexWritePriority>();
157 template <typename Lock>
158 void runManyReadLocksTestWithoutTokens() {
161 for (int i = 0; i < 1000; ++i) {
162 EXPECT_TRUE(lock.try_lock_shared());
164 for (int i = 0; i < 1000; ++i) {
165 lock.unlock_shared();
167 EXPECT_TRUE(lock.try_lock());
171 TEST(SharedMutex, many_read_locks_without_tokens) {
172 runManyReadLocksTestWithoutTokens<SharedMutexReadPriority>();
173 runManyReadLocksTestWithoutTokens<SharedMutexWritePriority>();
176 template <typename Lock>
177 void runTimeoutInPastTest() {
180 EXPECT_TRUE(lock.try_lock_for(milliseconds(0)));
182 EXPECT_TRUE(lock.try_lock_for(milliseconds(-1)));
184 EXPECT_TRUE(lock.try_lock_shared_for(milliseconds(0)));
185 lock.unlock_shared();
186 EXPECT_TRUE(lock.try_lock_shared_for(milliseconds(-1)));
187 lock.unlock_shared();
188 EXPECT_TRUE(lock.try_lock_until(system_clock::now() - milliseconds(1)));
191 lock.try_lock_shared_until(system_clock::now() - milliseconds(1)));
192 lock.unlock_shared();
193 EXPECT_TRUE(lock.try_lock_until(steady_clock::now() - milliseconds(1)));
196 lock.try_lock_shared_until(steady_clock::now() - milliseconds(1)));
197 lock.unlock_shared();
200 TEST(SharedMutex, timeout_in_past) {
201 runTimeoutInPastTest<SharedMutexReadPriority>();
202 runTimeoutInPastTest<SharedMutexWritePriority>();
205 template <class Func>
206 bool funcHasDuration(milliseconds expectedDuration, Func func) {
207 // elapsed time should eventually fall within expectedDuration +- 25%
208 for (int tries = 0; tries < 100; ++tries) {
209 auto start = steady_clock::now();
211 auto elapsed = steady_clock::now() - start;
212 if (elapsed > expectedDuration - expectedDuration / 4 &&
213 elapsed < expectedDuration + expectedDuration / 4) {
220 template <typename Lock>
221 void runFailingTryTimeoutTest() {
224 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
225 EXPECT_FALSE(lock.try_lock_for(milliseconds(10)));
227 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
228 typename Lock::Token token;
229 EXPECT_FALSE(lock.try_lock_shared_for(milliseconds(10), token));
231 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
232 EXPECT_FALSE(lock.try_lock_upgrade_for(milliseconds(10)));
234 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
235 EXPECT_FALSE(lock.try_lock_until(steady_clock::now() + milliseconds(10)));
237 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
238 typename Lock::Token token;
239 EXPECT_FALSE(lock.try_lock_shared_until(
240 steady_clock::now() + milliseconds(10), token));
242 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
244 lock.try_lock_upgrade_until(steady_clock::now() + milliseconds(10)));
246 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
247 EXPECT_FALSE(lock.try_lock_until(system_clock::now() + milliseconds(10)));
249 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
250 typename Lock::Token token;
251 EXPECT_FALSE(lock.try_lock_shared_until(
252 system_clock::now() + milliseconds(10), token));
254 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
256 lock.try_lock_upgrade_until(system_clock::now() + milliseconds(10)));
261 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
262 EXPECT_FALSE(lock.try_lock_for(milliseconds(10)));
264 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
265 EXPECT_FALSE(lock.try_lock_until(steady_clock::now() + milliseconds(10)));
267 EXPECT_TRUE(funcHasDuration(milliseconds(10), [&] {
268 EXPECT_FALSE(lock.try_lock_until(system_clock::now() + milliseconds(10)));
270 lock.unlock_shared();
273 for (int p = 0; p < 8; ++p) {
274 EXPECT_FALSE(lock.try_lock_for(nanoseconds(1 << p)));
278 for (int p = 0; p < 8; ++p) {
279 typename Lock::ReadHolder holder1(lock);
280 typename Lock::ReadHolder holder2(lock);
281 typename Lock::ReadHolder holder3(lock);
282 EXPECT_FALSE(lock.try_lock_for(nanoseconds(1 << p)));
286 TEST(SharedMutex, failing_try_timeout) {
287 runFailingTryTimeoutTest<SharedMutexReadPriority>();
288 runFailingTryTimeoutTest<SharedMutexWritePriority>();
291 template <typename Lock>
292 void runBasicUpgradeTest() {
294 typename Lock::Token token1;
295 typename Lock::Token token2;
298 EXPECT_FALSE(lock.try_lock());
299 EXPECT_TRUE(lock.try_lock_shared(token1));
300 lock.unlock_shared(token1);
301 lock.unlock_upgrade();
304 lock.unlock_upgrade_and_lock();
305 EXPECT_FALSE(lock.try_lock_shared(token1));
309 lock.unlock_upgrade_and_lock_shared(token1);
311 lock.unlock_upgrade_and_lock_shared(token2);
312 lock.unlock_shared(token1);
313 lock.unlock_shared(token2);
316 lock.unlock_and_lock_upgrade();
317 EXPECT_TRUE(lock.try_lock_shared(token1));
318 lock.unlock_upgrade();
319 lock.unlock_shared(token1);
322 TEST(SharedMutex, basic_upgrade_tests) {
323 runBasicUpgradeTest<SharedMutexReadPriority>();
324 runBasicUpgradeTest<SharedMutexWritePriority>();
327 TEST(SharedMutex, read_has_prio) {
328 SharedMutexReadPriority lock;
329 SharedMutexToken token1;
330 SharedMutexToken token2;
331 lock.lock_shared(token1);
332 bool exclusiveAcquired = false;
333 auto writer = thread([&] {
335 exclusiveAcquired = true;
339 // lock() can't complete until we unlock token1, but it should stake
340 // its claim with regards to other exclusive or upgrade locks. We can
341 // use try_lock_upgrade to poll for that eventuality.
342 while (lock.try_lock_upgrade()) {
343 lock.unlock_upgrade();
344 this_thread::yield();
346 EXPECT_FALSE(exclusiveAcquired);
348 // Even though lock() is stuck we should be able to get token2
349 EXPECT_TRUE(lock.try_lock_shared(token2));
350 lock.unlock_shared(token1);
351 lock.unlock_shared(token2);
353 EXPECT_TRUE(exclusiveAcquired);
356 TEST(SharedMutex, write_has_prio) {
357 SharedMutexWritePriority lock;
358 SharedMutexToken token1;
359 SharedMutexToken token2;
360 lock.lock_shared(token1);
361 auto writer = thread([&] {
366 // eventually lock() should block readers
367 while (lock.try_lock_shared(token2)) {
368 lock.unlock_shared(token2);
369 this_thread::yield();
372 lock.unlock_shared(token1);
377 SharedMutexToken token;
379 template <typename T>
384 template <typename T>
385 void unlock(T* lock) {
389 template <typename T>
390 void lock_shared(T* lock) {
391 lock->lock_shared(token);
394 template <typename T>
395 void unlock_shared(T* lock) {
396 lock->unlock_shared(token);
401 template <typename T>
406 template <typename T>
407 void unlock(T* lock) {
411 template <typename T>
412 void lock_shared(T* lock) {
416 template <typename T>
417 void unlock_shared(T* lock) {
418 lock->unlock_shared();
423 template <typename T>
428 template <typename T>
429 void unlock(T* lock) {
433 template <typename T>
434 void lock_shared(T* lock) {
438 template <typename T>
439 void unlock_shared(T* lock) {
445 pthread_rwlock_t lock_;
447 PosixRWLock() { pthread_rwlock_init(&lock_, nullptr); }
449 ~PosixRWLock() { pthread_rwlock_destroy(&lock_); }
451 void lock() { pthread_rwlock_wrlock(&lock_); }
453 void unlock() { pthread_rwlock_unlock(&lock_); }
455 void lock_shared() { pthread_rwlock_rdlock(&lock_); }
457 void unlock_shared() { pthread_rwlock_unlock(&lock_); }
461 pthread_mutex_t lock_;
463 PosixMutex() { pthread_mutex_init(&lock_, nullptr); }
465 ~PosixMutex() { pthread_mutex_destroy(&lock_); }
467 void lock() { pthread_mutex_lock(&lock_); }
469 void unlock() { pthread_mutex_unlock(&lock_); }
471 void lock_shared() { pthread_mutex_lock(&lock_); }
473 void unlock_shared() { pthread_mutex_unlock(&lock_); }
476 template <template <typename> class Atom, typename Lock, typename Locker>
477 static void runContendedReaders(size_t numOps,
479 bool useSeparateLocks) {
483 int valueProtectedByLock = 10;
486 Atom<bool> go(false);
487 Atom<bool>* goPtr = &go; // workaround for clang bug
488 vector<thread> threads(numThreads);
491 for (size_t t = 0; t < numThreads; ++t) {
492 threads[t] = DSched::thread([&, t, numThreads] {
494 Lock* lock = useSeparateLocks ? &privateLock : &globalLock;
496 while (!goPtr->load()) {
497 this_thread::yield();
499 for (size_t op = t; op < numOps; op += numThreads) {
500 locker.lock_shared(lock);
501 // note: folly::doNotOptimizeAway reads and writes to its arg,
502 // so the following two lines are very different than a call
503 // to folly::doNotOptimizeAway(valueProtectedByLock);
504 auto copy = valueProtectedByLock;
505 folly::doNotOptimizeAway(copy);
506 locker.unlock_shared(lock);
513 for (auto& thr : threads) {
518 static void folly_rwspin_reads(uint numOps,
520 bool useSeparateLocks) {
521 runContendedReaders<atomic, RWSpinLock, Locker>(
522 numOps, numThreads, useSeparateLocks);
525 static void shmtx_wr_pri_reads(uint numOps,
527 bool useSeparateLocks) {
528 runContendedReaders<atomic, SharedMutexWritePriority, TokenLocker>(
529 numOps, numThreads, useSeparateLocks);
532 static void shmtx_w_bare_reads(uint numOps,
534 bool useSeparateLocks) {
535 runContendedReaders<atomic, SharedMutexWritePriority, Locker>(
536 numOps, numThreads, useSeparateLocks);
539 static void shmtx_rd_pri_reads(uint numOps,
541 bool useSeparateLocks) {
542 runContendedReaders<atomic, SharedMutexReadPriority, TokenLocker>(
543 numOps, numThreads, useSeparateLocks);
546 static void shmtx_r_bare_reads(uint numOps,
548 bool useSeparateLocks) {
549 runContendedReaders<atomic, SharedMutexReadPriority, Locker>(
550 numOps, numThreads, useSeparateLocks);
553 static void folly_ticket_reads(uint numOps,
555 bool useSeparateLocks) {
556 runContendedReaders<atomic, RWTicketSpinLock64, Locker>(
557 numOps, numThreads, useSeparateLocks);
560 static void boost_shared_reads(uint numOps,
562 bool useSeparateLocks) {
563 runContendedReaders<atomic, boost::shared_mutex, Locker>(
564 numOps, numThreads, useSeparateLocks);
567 static void pthrd_rwlock_reads(uint numOps,
569 bool useSeparateLocks) {
570 runContendedReaders<atomic, PosixRWLock, Locker>(
571 numOps, numThreads, useSeparateLocks);
574 template <template <typename> class Atom, typename Lock, typename Locker>
575 static void runMixed(size_t numOps,
577 double writeFraction,
578 bool useSeparateLocks) {
582 int valueProtectedByLock = 0;
585 Atom<bool> go(false);
586 Atom<bool>* goPtr = &go; // workaround for clang bug
587 vector<thread> threads(numThreads);
590 for (size_t t = 0; t < numThreads; ++t) {
591 threads[t] = DSched::thread([&, t, numThreads] {
592 struct drand48_data buffer;
593 srand48_r(t, &buffer);
594 long writeThreshold = writeFraction * 0x7fffffff;
596 Lock* lock = useSeparateLocks ? &privateLock : &globalLock;
598 while (!goPtr->load()) {
599 this_thread::yield();
601 for (size_t op = t; op < numOps; op += numThreads) {
603 lrand48_r(&buffer, &randVal);
604 bool writeOp = randVal < writeThreshold;
607 if (!useSeparateLocks) {
608 ++valueProtectedByLock;
612 locker.lock_shared(lock);
613 auto v = valueProtectedByLock;
614 folly::doNotOptimizeAway(v);
615 locker.unlock_shared(lock);
623 for (auto& thr : threads) {
628 static void folly_rwspin(size_t numOps,
630 double writeFraction,
631 bool useSeparateLocks) {
632 runMixed<atomic, RWSpinLock, Locker>(
633 numOps, numThreads, writeFraction, useSeparateLocks);
636 static void shmtx_wr_pri(uint numOps,
638 double writeFraction,
639 bool useSeparateLocks) {
640 runMixed<atomic, SharedMutexWritePriority, TokenLocker>(
641 numOps, numThreads, writeFraction, useSeparateLocks);
644 static void shmtx_w_bare(uint numOps,
646 double writeFraction,
647 bool useSeparateLocks) {
648 runMixed<atomic, SharedMutexWritePriority, Locker>(
649 numOps, numThreads, writeFraction, useSeparateLocks);
652 static void shmtx_rd_pri(uint numOps,
654 double writeFraction,
655 bool useSeparateLocks) {
656 runMixed<atomic, SharedMutexReadPriority, TokenLocker>(
657 numOps, numThreads, writeFraction, useSeparateLocks);
660 static void shmtx_r_bare(uint numOps,
662 double writeFraction,
663 bool useSeparateLocks) {
664 runMixed<atomic, SharedMutexReadPriority, Locker>(
665 numOps, numThreads, writeFraction, useSeparateLocks);
668 static void folly_ticket(size_t numOps,
670 double writeFraction,
671 bool useSeparateLocks) {
672 runMixed<atomic, RWTicketSpinLock64, Locker>(
673 numOps, numThreads, writeFraction, useSeparateLocks);
676 static void boost_shared(size_t numOps,
678 double writeFraction,
679 bool useSeparateLocks) {
680 runMixed<atomic, boost::shared_mutex, Locker>(
681 numOps, numThreads, writeFraction, useSeparateLocks);
684 static void pthrd_rwlock(size_t numOps,
686 double writeFraction,
687 bool useSeparateLocks) {
688 runMixed<atomic, PosixRWLock, Locker>(
689 numOps, numThreads, writeFraction, useSeparateLocks);
692 static void pthrd_mutex_(size_t numOps,
694 double writeFraction,
695 bool useSeparateLocks) {
696 runMixed<atomic, PosixMutex, Locker>(
697 numOps, numThreads, writeFraction, useSeparateLocks);
700 template <typename Lock, template <typename> class Atom>
701 static void runAllAndValidate(size_t numOps, size_t numThreads) {
703 Atom<int> globalExclusiveCount(0);
704 Atom<int> globalUpgradeCount(0);
705 Atom<int> globalSharedCount(0);
707 Atom<bool> go(false);
709 // clang crashes on access to Atom<> captured by ref in closure
710 Atom<int>* globalExclusiveCountPtr = &globalExclusiveCount;
711 Atom<int>* globalUpgradeCountPtr = &globalUpgradeCount;
712 Atom<int>* globalSharedCountPtr = &globalSharedCount;
713 Atom<bool>* goPtr = &go;
715 vector<thread> threads(numThreads);
718 for (size_t t = 0; t < numThreads; ++t) {
719 threads[t] = DSched::thread([&, t, numThreads] {
720 struct drand48_data buffer;
721 srand48_r(t, &buffer);
723 bool exclusive = false;
724 bool upgrade = false;
726 bool ourGlobalTokenUsed = false;
727 SharedMutexToken ourGlobalToken;
730 vector<SharedMutexToken> privateTokens;
732 while (!goPtr->load()) {
733 this_thread::yield();
735 for (size_t op = t; op < numOps; op += numThreads) {
736 // randVal in [0,1000)
738 lrand48_r(&buffer, &randVal);
739 randVal = (long)((randVal * (uint64_t)1000) / 0x7fffffff);
741 // make as many assertions as possible about the global state
743 EXPECT_EQ(1, globalExclusiveCountPtr->load(memory_order_acquire));
744 EXPECT_EQ(0, globalUpgradeCountPtr->load(memory_order_acquire));
745 EXPECT_EQ(0, globalSharedCountPtr->load(memory_order_acquire));
748 EXPECT_EQ(0, globalExclusiveCountPtr->load(memory_order_acquire));
749 EXPECT_EQ(1, globalUpgradeCountPtr->load(memory_order_acquire));
752 EXPECT_EQ(0, globalExclusiveCountPtr->load(memory_order_acquire));
753 EXPECT_TRUE(globalSharedCountPtr->load(memory_order_acquire) > 0);
755 EXPECT_FALSE(ourGlobalTokenUsed);
758 // independent 20% chance we do something to the private lock
760 // it's okay to take multiple private shared locks because
761 // we never take an exclusive lock, so reader versus writer
762 // priority doesn't cause deadlocks
763 if (randVal < 100 && privateTokens.size() > 0) {
764 auto i = randVal % privateTokens.size();
765 privateLock.unlock_shared(privateTokens[i]);
766 privateTokens.erase(privateTokens.begin() + i);
768 SharedMutexToken token;
769 privateLock.lock_shared(token);
770 privateTokens.push_back(token);
775 // if we've got a lock, the only thing we can do is release it
776 // or transform it into a different kind of lock
779 --*globalExclusiveCountPtr;
782 } else if (randVal < 700) {
783 globalLock.unlock_and_lock_shared();
784 ++*globalSharedCountPtr;
786 } else if (randVal < 900) {
787 globalLock.unlock_and_lock_shared(ourGlobalToken);
788 ++*globalSharedCountPtr;
790 ourGlobalTokenUsed = true;
792 globalLock.unlock_and_lock_upgrade();
793 ++*globalUpgradeCountPtr;
796 } else if (upgrade) {
798 --*globalUpgradeCountPtr;
800 globalLock.unlock_upgrade();
801 } else if (randVal < 700) {
802 globalLock.unlock_upgrade_and_lock_shared();
803 ++*globalSharedCountPtr;
805 } else if (randVal < 900) {
806 globalLock.unlock_upgrade_and_lock_shared(ourGlobalToken);
807 ++*globalSharedCountPtr;
809 ourGlobalTokenUsed = true;
811 globalLock.unlock_upgrade_and_lock();
812 ++*globalExclusiveCountPtr;
817 --*globalSharedCountPtr;
818 if (ourGlobalTokenUsed) {
819 globalLock.unlock_shared(ourGlobalToken);
820 ourGlobalTokenUsed = false;
822 globalLock.unlock_shared();
824 } else if (randVal < 400) {
825 // 40% chance of shared lock with token, 5 ways to get it
827 // delta t goes from -1 millis to 7 millis
828 auto dt = microseconds(10 * (randVal - 100));
831 globalLock.lock_shared(ourGlobalToken);
833 } else if (randVal < 500) {
834 shared = globalLock.try_lock_shared(ourGlobalToken);
835 } else if (randVal < 600) {
836 shared = globalLock.try_lock_shared_for(dt, ourGlobalToken);
837 } else if (randVal < 800) {
838 shared = globalLock.try_lock_shared_until(
839 system_clock::now() + dt, ourGlobalToken);
842 ourGlobalTokenUsed = true;
843 ++*globalSharedCountPtr;
845 } else if (randVal < 800) {
846 // 40% chance of shared lock without token
847 auto dt = microseconds(10 * (randVal - 100));
849 globalLock.lock_shared();
851 } else if (randVal < 500) {
852 shared = globalLock.try_lock_shared();
853 } else if (randVal < 600) {
854 shared = globalLock.try_lock_shared_for(dt);
855 } else if (randVal < 800) {
856 shared = globalLock.try_lock_shared_until(
857 system_clock::now() + dt);
860 ++*globalSharedCountPtr;
862 } else if (randVal < 900) {
863 // 10% change of upgrade lock
864 globalLock.lock_upgrade();
866 ++*globalUpgradeCountPtr;
868 // 10% chance of exclusive lock, 5 ways to get it
870 // delta t goes from -1 millis to 9 millis
871 auto dt = microseconds(100 * (randVal - 910));
876 } else if (randVal < 500) {
877 exclusive = globalLock.try_lock();
878 } else if (randVal < 600) {
879 exclusive = globalLock.try_lock_for(dt);
880 } else if (randVal < 700) {
881 exclusive = globalLock.try_lock_until(steady_clock::now() + dt);
883 exclusive = globalLock.try_lock_until(system_clock::now() + dt);
886 ++*globalExclusiveCountPtr;
892 --*globalExclusiveCountPtr;
896 --*globalUpgradeCountPtr;
897 globalLock.unlock_upgrade();
900 --*globalSharedCountPtr;
901 if (ourGlobalTokenUsed) {
902 globalLock.unlock_shared(ourGlobalToken);
903 ourGlobalTokenUsed = false;
905 globalLock.unlock_shared();
908 for (auto& token : privateTokens) {
909 privateLock.unlock_shared(token);
916 for (auto& thr : threads) {
921 TEST(SharedMutex, deterministic_concurrent_readers_of_one_lock_read_prio) {
922 for (int pass = 0; pass < 3; ++pass) {
923 DSched sched(DSched::uniform(pass));
924 runContendedReaders<DeterministicAtomic,
925 DSharedMutexReadPriority,
926 Locker>(1000, 3, false);
930 TEST(SharedMutex, deterministic_concurrent_readers_of_one_lock_write_prio) {
931 for (int pass = 0; pass < 3; ++pass) {
932 DSched sched(DSched::uniform(pass));
933 runContendedReaders<DeterministicAtomic,
934 DSharedMutexWritePriority,
935 Locker>(1000, 3, false);
939 TEST(SharedMutex, concurrent_readers_of_one_lock_read_prio) {
940 for (int pass = 0; pass < 10; ++pass) {
941 runContendedReaders<atomic, SharedMutexReadPriority, Locker>(
946 TEST(SharedMutex, concurrent_readers_of_one_lock_write_prio) {
947 for (int pass = 0; pass < 10; ++pass) {
948 runContendedReaders<atomic, SharedMutexWritePriority, Locker>(
953 TEST(SharedMutex, deterministic_readers_of_concurrent_locks_read_prio) {
954 for (int pass = 0; pass < 3; ++pass) {
955 DSched sched(DSched::uniform(pass));
956 runContendedReaders<DeterministicAtomic,
957 DSharedMutexReadPriority,
958 Locker>(1000, 3, true);
962 TEST(SharedMutex, deterministic_readers_of_concurrent_locks_write_prio) {
963 for (int pass = 0; pass < 3; ++pass) {
964 DSched sched(DSched::uniform(pass));
965 runContendedReaders<DeterministicAtomic,
966 DSharedMutexWritePriority,
967 Locker>(1000, 3, true);
971 TEST(SharedMutex, readers_of_concurrent_locks_read_prio) {
972 for (int pass = 0; pass < 10; ++pass) {
973 runContendedReaders<atomic, SharedMutexReadPriority, TokenLocker>(
978 TEST(SharedMutex, readers_of_concurrent_locks_write_prio) {
979 for (int pass = 0; pass < 10; ++pass) {
980 runContendedReaders<atomic, SharedMutexWritePriority, TokenLocker>(
985 TEST(SharedMutex, deterministic_mixed_mostly_read_read_prio) {
986 for (int pass = 0; pass < 3; ++pass) {
987 DSched sched(DSched::uniform(pass));
988 runMixed<DeterministicAtomic, DSharedMutexReadPriority, Locker>(
989 1000, 3, 0.1, false);
993 TEST(SharedMutex, deterministic_mixed_mostly_read_write_prio) {
994 for (int pass = 0; pass < 3; ++pass) {
995 DSched sched(DSched::uniform(pass));
996 runMixed<DeterministicAtomic, DSharedMutexWritePriority, Locker>(
997 1000, 3, 0.1, false);
1001 TEST(SharedMutex, mixed_mostly_read_read_prio) {
1002 for (int pass = 0; pass < 5; ++pass) {
1003 runMixed<atomic, SharedMutexReadPriority, TokenLocker>(
1004 50000, 32, 0.1, false);
1008 TEST(SharedMutex, mixed_mostly_read_write_prio) {
1009 for (int pass = 0; pass < 5; ++pass) {
1010 runMixed<atomic, SharedMutexWritePriority, TokenLocker>(
1011 50000, 32, 0.1, false);
1015 TEST(SharedMutex, deterministic_mixed_mostly_write_read_prio) {
1016 for (int pass = 0; pass < 1; ++pass) {
1017 DSched sched(DSched::uniform(pass));
1018 runMixed<DeterministicAtomic, DSharedMutexReadPriority, TokenLocker>(
1019 1000, 10, 0.9, false);
1023 TEST(SharedMutex, deterministic_mixed_mostly_write_write_prio) {
1024 for (int pass = 0; pass < 1; ++pass) {
1025 DSched sched(DSched::uniform(pass));
1026 runMixed<DeterministicAtomic, DSharedMutexWritePriority, TokenLocker>(
1027 1000, 10, 0.9, false);
1031 TEST(SharedMutex, deterministic_lost_wakeup_write_prio) {
1032 for (int pass = 0; pass < 10; ++pass) {
1033 DSched sched(DSched::uniformSubset(pass, 2, 200));
1034 runMixed<DeterministicAtomic, DSharedMutexWritePriority, TokenLocker>(
1035 1000, 3, 1.0, false);
1039 TEST(SharedMutex, mixed_mostly_write_read_prio) {
1040 for (int pass = 0; pass < 5; ++pass) {
1041 runMixed<atomic, SharedMutexReadPriority, TokenLocker>(
1042 50000, 300, 0.9, false);
1046 TEST(SharedMutex, mixed_mostly_write_write_prio) {
1047 for (int pass = 0; pass < 5; ++pass) {
1048 runMixed<atomic, SharedMutexWritePriority, TokenLocker>(
1049 50000, 300, 0.9, false);
1053 TEST(SharedMutex, deterministic_all_ops_read_prio) {
1054 for (int pass = 0; pass < 5; ++pass) {
1055 DSched sched(DSched::uniform(pass));
1056 runAllAndValidate<DSharedMutexReadPriority, DeterministicAtomic>(1000, 8);
1060 TEST(SharedMutex, deterministic_all_ops_write_prio) {
1061 for (int pass = 0; pass < 5; ++pass) {
1062 DSched sched(DSched::uniform(pass));
1063 runAllAndValidate<DSharedMutexWritePriority, DeterministicAtomic>(1000, 8);
1067 TEST(SharedMutex, all_ops_read_prio) {
1068 for (int pass = 0; pass < 5; ++pass) {
1069 runAllAndValidate<SharedMutexReadPriority, atomic>(100000, 32);
1073 TEST(SharedMutex, all_ops_write_prio) {
1074 for (int pass = 0; pass < 5; ++pass) {
1075 runAllAndValidate<SharedMutexWritePriority, atomic>(100000, 32);
1079 FOLLY_ASSUME_FBVECTOR_COMPATIBLE(
1080 boost::optional<boost::optional<SharedMutexToken>>)
1082 // Setup is a set of threads that either grab a shared lock, or exclusive
1083 // and then downgrade it, or upgrade then upgrade and downgrade, then
1084 // enqueue the shared lock to a second set of threads that just performs
1085 // unlocks. Half of the shared locks use tokens, the others don't.
1086 template <typename Lock, template <typename> class Atom>
1087 static void runRemoteUnlock(size_t numOps,
1088 double preWriteFraction,
1089 double preUpgradeFraction,
1090 size_t numSendingThreads,
1091 size_t numReceivingThreads) {
1093 MPMCQueue<boost::optional<boost::optional<SharedMutexToken>>, Atom>
1095 auto queuePtr = &queue; // workaround for clang crash
1097 Atom<bool> go(false);
1098 auto goPtr = &go; // workaround for clang crash
1099 Atom<int> pendingSenders(numSendingThreads);
1100 auto pendingSendersPtr = &pendingSenders; // workaround for clang crash
1101 vector<thread> threads(numSendingThreads + numReceivingThreads);
1104 for (size_t t = 0; t < threads.size(); ++t) {
1105 threads[t] = DSched::thread([&, t, numSendingThreads] {
1106 if (t >= numSendingThreads) {
1108 typename decltype(queue)::value_type elem;
1110 queuePtr->blockingRead(elem);
1112 // EOF, pass the EOF token
1113 queuePtr->blockingWrite(std::move(elem));
1117 globalLock.unlock_shared(**elem);
1119 globalLock.unlock_shared();
1124 // else we're a sender
1126 struct drand48_data buffer;
1127 srand48_r(t, &buffer);
1129 while (!goPtr->load()) {
1130 this_thread::yield();
1132 for (size_t op = t; op < numOps; op += numSendingThreads) {
1133 long unscaledRandVal;
1134 lrand48_r(&buffer, &unscaledRandVal);
1137 double randVal = ((double)unscaledRandVal) / 0x7fffffff;
1139 // extract a bit and rescale
1140 bool useToken = randVal >= 0.5;
1141 randVal = (randVal - (useToken ? 0.5 : 0.0)) * 2;
1143 boost::optional<SharedMutexToken> maybeToken;
1146 SharedMutexToken token;
1147 if (randVal < preWriteFraction) {
1149 globalLock.unlock_and_lock_shared(token);
1150 } else if (randVal < preWriteFraction + preUpgradeFraction / 2) {
1151 globalLock.lock_upgrade();
1152 globalLock.unlock_upgrade_and_lock_shared(token);
1153 } else if (randVal < preWriteFraction + preUpgradeFraction) {
1154 globalLock.lock_upgrade();
1155 globalLock.unlock_upgrade_and_lock();
1156 globalLock.unlock_and_lock_shared(token);
1158 globalLock.lock_shared(token);
1162 if (randVal < preWriteFraction) {
1164 globalLock.unlock_and_lock_shared();
1165 } else if (randVal < preWriteFraction + preUpgradeFraction / 2) {
1166 globalLock.lock_upgrade();
1167 globalLock.unlock_upgrade_and_lock_shared();
1168 } else if (randVal < preWriteFraction + preUpgradeFraction) {
1169 globalLock.lock_upgrade();
1170 globalLock.unlock_upgrade_and_lock();
1171 globalLock.unlock_and_lock_shared();
1173 globalLock.lock_shared();
1177 // blockingWrite is emplace-like, so this automatically adds
1178 // another level of wrapping
1179 queuePtr->blockingWrite(maybeToken);
1181 if (--*pendingSendersPtr == 0) {
1182 queuePtr->blockingWrite(boost::none);
1189 for (auto& thr : threads) {
1194 TEST(SharedMutex, deterministic_remote_write_prio) {
1195 for (int pass = 0; pass < 1; ++pass) {
1196 DSched sched(DSched::uniform(pass));
1197 runRemoteUnlock<DSharedMutexWritePriority, DeterministicAtomic>(
1198 500, 0.1, 0.1, 5, 5);
1202 TEST(SharedMutex, deterministic_remote_read_prio) {
1203 for (int pass = 0; pass < 1; ++pass) {
1204 DSched sched(DSched::uniform(pass));
1205 runRemoteUnlock<DSharedMutexReadPriority, DeterministicAtomic>(
1206 500, 0.1, 0.1, 5, 5);
1210 TEST(SharedMutex, remote_write_prio) {
1211 for (int pass = 0; pass < 10; ++pass) {
1212 runRemoteUnlock<SharedMutexWritePriority, atomic>(100000, 0.1, 0.1, 5, 5);
1216 TEST(SharedMutex, remote_read_prio) {
1217 for (int pass = 0; pass < 100; ++pass) {
1218 runRemoteUnlock<SharedMutexReadPriority, atomic>(100000, 0.1, 0.1, 5, 5);
1222 static void burn(size_t n) {
1223 for (size_t i = 0; i < n; ++i) {
1224 folly::doNotOptimizeAway(i);
1228 // Two threads and three locks, arranged so that they have to proceed
1229 // in turn with reader/writer conflict
1230 template <typename Lock, template <typename> class Atom = atomic>
1231 static void runPingPong(size_t numRounds, size_t burnCount) {
1234 pair<Lock, char[56]> locks[3];
1239 auto availPtr = &avail; // workaround for clang crash
1240 Atom<bool> go(false);
1241 auto goPtr = &go; // workaround for clang crash
1242 vector<thread> threads(2);
1244 locks[0].first.lock();
1245 locks[1].first.lock();
1246 locks[2].first.lock_shared();
1249 threads[0] = DSched::thread([&] {
1251 while (!goPtr->load()) {
1252 this_thread::yield();
1254 for (size_t i = 0; i < numRounds; ++i) {
1255 locks[i % 3].first.unlock();
1256 locks[(i + 2) % 3].first.lock();
1260 threads[1] = DSched::thread([&] {
1262 while (!goPtr->load()) {
1263 this_thread::yield();
1265 for (size_t i = 0; i < numRounds; ++i) {
1266 locks[i % 3].first.lock_shared();
1268 locks[(i + 2) % 3].first.unlock_shared();
1272 while (avail.load() < 2) {
1273 this_thread::yield();
1278 for (auto& thr : threads) {
1281 locks[numRounds % 3].first.unlock();
1282 locks[(numRounds + 1) % 3].first.unlock();
1283 locks[(numRounds + 2) % 3].first.unlock_shared();
1286 static void folly_rwspin_ping_pong(size_t n, size_t scale, size_t burnCount) {
1287 runPingPong<RWSpinLock>(n / scale, burnCount);
1290 static void shmtx_w_bare_ping_pong(size_t n, size_t scale, size_t burnCount) {
1291 runPingPong<SharedMutexWritePriority>(n / scale, burnCount);
1294 static void shmtx_r_bare_ping_pong(size_t n, size_t scale, size_t burnCount) {
1295 runPingPong<SharedMutexReadPriority>(n / scale, burnCount);
1298 static void folly_ticket_ping_pong(size_t n, size_t scale, size_t burnCount) {
1299 runPingPong<RWTicketSpinLock64>(n / scale, burnCount);
1302 static void boost_shared_ping_pong(size_t n, size_t scale, size_t burnCount) {
1303 runPingPong<boost::shared_mutex>(n / scale, burnCount);
1306 static void pthrd_rwlock_ping_pong(size_t n, size_t scale, size_t burnCount) {
1307 runPingPong<PosixRWLock>(n / scale, burnCount);
1310 TEST(SharedMutex, deterministic_ping_pong_write_prio) {
1311 for (int pass = 0; pass < 1; ++pass) {
1312 DSched sched(DSched::uniform(pass));
1313 runPingPong<DSharedMutexWritePriority, DeterministicAtomic>(500, 0);
1317 TEST(SharedMutex, deterministic_ping_pong_read_prio) {
1318 for (int pass = 0; pass < 1; ++pass) {
1319 DSched sched(DSched::uniform(pass));
1320 runPingPong<DSharedMutexReadPriority, DeterministicAtomic>(500, 0);
1324 TEST(SharedMutex, ping_pong_write_prio) {
1325 for (int pass = 0; pass < 1; ++pass) {
1326 runPingPong<SharedMutexWritePriority, atomic>(50000, 0);
1330 TEST(SharedMutex, ping_pong_read_prio) {
1331 for (int pass = 0; pass < 1; ++pass) {
1332 runPingPong<SharedMutexReadPriority, atomic>(50000, 0);
1336 // This is here so you can tell how much of the runtime reported by the
1337 // more complex harnesses is due to the harness, although due to the
1338 // magic of compiler optimization it may also be slower
1339 BENCHMARK(single_thread_lock_shared_unlock_shared, iters) {
1341 for (size_t n = 0; n < iters; ++n) {
1342 SharedMutex::Token token;
1343 lock.lock_shared(token);
1344 folly::doNotOptimizeAway(0);
1345 lock.unlock_shared(token);
1349 BENCHMARK(single_thread_lock_unlock, iters) {
1351 for (size_t n = 0; n < iters; ++n) {
1353 folly::doNotOptimizeAway(0);
1358 #define BENCH_BASE(args...) BENCHMARK_NAMED_PARAM(args)
1359 #define BENCH_REL(args...) BENCHMARK_RELATIVE_NAMED_PARAM(args)
1361 // 100% reads. Best-case scenario for deferred locks. Lock is colocated
1362 // with read data, so inline lock takes cache miss every time but deferred
1363 // lock has only cache hits and local access.
1364 BENCHMARK_DRAW_LINE()
1365 BENCHMARK_DRAW_LINE()
1366 BENCH_BASE(folly_rwspin_reads, 1thread, 1, false)
1367 BENCH_REL (shmtx_wr_pri_reads, 1thread, 1, false)
1368 BENCH_REL (shmtx_w_bare_reads, 1thread, 1, false)
1369 BENCH_REL (shmtx_rd_pri_reads, 1thread, 1, false)
1370 BENCH_REL (shmtx_r_bare_reads, 1thread, 1, false)
1371 BENCH_REL (folly_ticket_reads, 1thread, 1, false)
1372 BENCH_REL (boost_shared_reads, 1thread, 1, false)
1373 BENCH_REL (pthrd_rwlock_reads, 1thread, 1, false)
1374 BENCHMARK_DRAW_LINE()
1375 BENCH_BASE(folly_rwspin_reads, 2thread, 2, false)
1376 BENCH_REL (shmtx_wr_pri_reads, 2thread, 2, false)
1377 BENCH_REL (shmtx_w_bare_reads, 2thread, 2, false)
1378 BENCH_REL (shmtx_rd_pri_reads, 2thread, 2, false)
1379 BENCH_REL (shmtx_r_bare_reads, 2thread, 2, false)
1380 BENCH_REL (folly_ticket_reads, 2thread, 2, false)
1381 BENCH_REL (boost_shared_reads, 2thread, 2, false)
1382 BENCH_REL (pthrd_rwlock_reads, 2thread, 2, false)
1383 BENCHMARK_DRAW_LINE()
1384 BENCH_BASE(folly_rwspin_reads, 4thread, 4, false)
1385 BENCH_REL (shmtx_wr_pri_reads, 4thread, 4, false)
1386 BENCH_REL (shmtx_w_bare_reads, 4thread, 4, false)
1387 BENCH_REL (shmtx_rd_pri_reads, 4thread, 4, false)
1388 BENCH_REL (shmtx_r_bare_reads, 4thread, 4, false)
1389 BENCH_REL (folly_ticket_reads, 4thread, 4, false)
1390 BENCH_REL (boost_shared_reads, 4thread, 4, false)
1391 BENCH_REL (pthrd_rwlock_reads, 4thread, 4, false)
1392 BENCHMARK_DRAW_LINE()
1393 BENCH_BASE(folly_rwspin_reads, 8thread, 8, false)
1394 BENCH_REL (shmtx_wr_pri_reads, 8thread, 8, false)
1395 BENCH_REL (shmtx_w_bare_reads, 8thread, 8, false)
1396 BENCH_REL (shmtx_rd_pri_reads, 8thread, 8, false)
1397 BENCH_REL (shmtx_r_bare_reads, 8thread, 8, false)
1398 BENCH_REL (folly_ticket_reads, 8thread, 8, false)
1399 BENCH_REL (boost_shared_reads, 8thread, 8, false)
1400 BENCH_REL (pthrd_rwlock_reads, 8thread, 8, false)
1401 BENCHMARK_DRAW_LINE()
1402 BENCH_BASE(folly_rwspin_reads, 16thread, 16, false)
1403 BENCH_REL (shmtx_wr_pri_reads, 16thread, 16, false)
1404 BENCH_REL (shmtx_w_bare_reads, 16thread, 16, false)
1405 BENCH_REL (shmtx_rd_pri_reads, 16thread, 16, false)
1406 BENCH_REL (shmtx_r_bare_reads, 16thread, 16, false)
1407 BENCH_REL (folly_ticket_reads, 16thread, 16, false)
1408 BENCH_REL (boost_shared_reads, 16thread, 16, false)
1409 BENCH_REL (pthrd_rwlock_reads, 16thread, 16, false)
1410 BENCHMARK_DRAW_LINE()
1411 BENCH_BASE(folly_rwspin_reads, 32thread, 32, false)
1412 BENCH_REL (shmtx_wr_pri_reads, 32thread, 32, false)
1413 BENCH_REL (shmtx_w_bare_reads, 32thread, 32, false)
1414 BENCH_REL (shmtx_rd_pri_reads, 32thread, 32, false)
1415 BENCH_REL (shmtx_r_bare_reads, 32thread, 32, false)
1416 BENCH_REL (folly_ticket_reads, 32thread, 32, false)
1417 BENCH_REL (boost_shared_reads, 32thread, 32, false)
1418 BENCH_REL (pthrd_rwlock_reads, 32thread, 32, false)
1419 BENCHMARK_DRAW_LINE()
1420 BENCH_BASE(folly_rwspin_reads, 64thread, 64, false)
1421 BENCH_REL (shmtx_wr_pri_reads, 64thread, 64, false)
1422 BENCH_REL (shmtx_w_bare_reads, 64thread, 64, false)
1423 BENCH_REL (shmtx_rd_pri_reads, 64thread, 64, false)
1424 BENCH_REL (shmtx_r_bare_reads, 64thread, 64, false)
1425 BENCH_REL (folly_ticket_reads, 64thread, 64, false)
1426 BENCH_REL (boost_shared_reads, 64thread, 64, false)
1427 BENCH_REL (pthrd_rwlock_reads, 64thread, 64, false)
1429 // 1 lock used by everybody, 100% writes. Threads only hurt, but it is
1430 // good to not fail catastrophically. Compare to single_thread_lock_unlock
1431 // to see the overhead of the generic driver (and its pseudo-random number
1432 // generator). pthrd_mutex_ is a pthread_mutex_t (default, not adaptive),
1433 // which is better than any of the reader-writer locks for this scenario.
1434 BENCHMARK_DRAW_LINE()
1435 BENCHMARK_DRAW_LINE()
1436 BENCH_BASE(folly_rwspin, 1thread_all_write, 1, 1.0, false)
1437 BENCH_REL (shmtx_wr_pri, 1thread_all_write, 1, 1.0, false)
1438 BENCH_REL (shmtx_rd_pri, 1thread_all_write, 1, 1.0, false)
1439 BENCH_REL (folly_ticket, 1thread_all_write, 1, 1.0, false)
1440 BENCH_REL (boost_shared, 1thread_all_write, 1, 1.0, false)
1441 BENCH_REL (pthrd_rwlock, 1thread_all_write, 1, 1.0, false)
1442 BENCH_REL (pthrd_mutex_, 1thread_all_write, 1, 1.0, false)
1443 BENCHMARK_DRAW_LINE()
1444 BENCH_BASE(folly_rwspin, 2thread_all_write, 2, 1.0, false)
1445 BENCH_REL (shmtx_wr_pri, 2thread_all_write, 2, 1.0, false)
1446 BENCH_REL (shmtx_rd_pri, 2thread_all_write, 2, 1.0, false)
1447 BENCH_REL (folly_ticket, 2thread_all_write, 2, 1.0, false)
1448 BENCH_REL (boost_shared, 2thread_all_write, 2, 1.0, false)
1449 BENCH_REL (pthrd_rwlock, 2thread_all_write, 2, 1.0, false)
1450 BENCH_REL (pthrd_mutex_, 2thread_all_write, 2, 1.0, false)
1451 BENCHMARK_DRAW_LINE()
1452 BENCH_BASE(folly_rwspin, 4thread_all_write, 4, 1.0, false)
1453 BENCH_REL (shmtx_wr_pri, 4thread_all_write, 4, 1.0, false)
1454 BENCH_REL (shmtx_rd_pri, 4thread_all_write, 4, 1.0, false)
1455 BENCH_REL (folly_ticket, 4thread_all_write, 4, 1.0, false)
1456 BENCH_REL (boost_shared, 4thread_all_write, 4, 1.0, false)
1457 BENCH_REL (pthrd_rwlock, 4thread_all_write, 4, 1.0, false)
1458 BENCH_REL (pthrd_mutex_, 4thread_all_write, 4, 1.0, false)
1459 BENCHMARK_DRAW_LINE()
1460 BENCH_BASE(folly_rwspin, 8thread_all_write, 8, 1.0, false)
1461 BENCH_REL (shmtx_wr_pri, 8thread_all_write, 8, 1.0, false)
1462 BENCH_REL (shmtx_rd_pri, 8thread_all_write, 8, 1.0, false)
1463 BENCH_REL (folly_ticket, 8thread_all_write, 8, 1.0, false)
1464 BENCH_REL (boost_shared, 8thread_all_write, 8, 1.0, false)
1465 BENCH_REL (pthrd_rwlock, 8thread_all_write, 8, 1.0, false)
1466 BENCH_REL (pthrd_mutex_, 8thread_all_write, 8, 1.0, false)
1467 BENCHMARK_DRAW_LINE()
1468 BENCH_BASE(folly_rwspin, 16thread_all_write, 16, 1.0, false)
1469 BENCH_REL (shmtx_wr_pri, 16thread_all_write, 16, 1.0, false)
1470 BENCH_REL (shmtx_rd_pri, 16thread_all_write, 16, 1.0, false)
1471 BENCH_REL (folly_ticket, 16thread_all_write, 16, 1.0, false)
1472 BENCH_REL (boost_shared, 16thread_all_write, 16, 1.0, false)
1473 BENCH_REL (pthrd_rwlock, 16thread_all_write, 16, 1.0, false)
1474 BENCH_REL (pthrd_mutex_, 16thread_all_write, 16, 1.0, false)
1475 BENCHMARK_DRAW_LINE()
1476 BENCH_BASE(folly_rwspin, 32thread_all_write, 32, 1.0, false)
1477 BENCH_REL (shmtx_wr_pri, 32thread_all_write, 32, 1.0, false)
1478 BENCH_REL (shmtx_rd_pri, 32thread_all_write, 32, 1.0, false)
1479 BENCH_REL (folly_ticket, 32thread_all_write, 32, 1.0, false)
1480 BENCH_REL (boost_shared, 32thread_all_write, 32, 1.0, false)
1481 BENCH_REL (pthrd_rwlock, 32thread_all_write, 32, 1.0, false)
1482 BENCH_REL (pthrd_mutex_, 32thread_all_write, 32, 1.0, false)
1483 BENCHMARK_DRAW_LINE()
1484 BENCH_BASE(folly_rwspin, 64thread_all_write, 64, 1.0, false)
1485 BENCH_REL (shmtx_wr_pri, 64thread_all_write, 64, 1.0, false)
1486 BENCH_REL (shmtx_rd_pri, 64thread_all_write, 64, 1.0, false)
1487 BENCH_REL (folly_ticket, 64thread_all_write, 64, 1.0, false)
1488 BENCH_REL (boost_shared, 64thread_all_write, 64, 1.0, false)
1489 BENCH_REL (pthrd_rwlock, 64thread_all_write, 64, 1.0, false)
1490 BENCH_REL (pthrd_mutex_, 64thread_all_write, 64, 1.0, false)
1492 // 1 lock used by everybody, 10% writes. Not much scaling to be had. Perf
1493 // is best at 1 thread, once you've got multiple threads > 8 threads hurts.
1494 BENCHMARK_DRAW_LINE()
1495 BENCHMARK_DRAW_LINE()
1496 BENCH_BASE(folly_rwspin, 1thread_10pct_write, 1, 0.10, false)
1497 BENCH_REL (shmtx_wr_pri, 1thread_10pct_write, 1, 0.10, false)
1498 BENCH_REL (shmtx_rd_pri, 1thread_10pct_write, 1, 0.10, false)
1499 BENCH_REL (folly_ticket, 1thread_10pct_write, 1, 0.10, false)
1500 BENCH_REL (boost_shared, 1thread_10pct_write, 1, 0.10, false)
1501 BENCH_REL (pthrd_rwlock, 1thread_10pct_write, 1, 0.10, false)
1502 BENCHMARK_DRAW_LINE()
1503 BENCH_BASE(folly_rwspin, 2thread_10pct_write, 2, 0.10, false)
1504 BENCH_REL (shmtx_wr_pri, 2thread_10pct_write, 2, 0.10, false)
1505 BENCH_REL (shmtx_rd_pri, 2thread_10pct_write, 2, 0.10, false)
1506 BENCH_REL (folly_ticket, 2thread_10pct_write, 2, 0.10, false)
1507 BENCH_REL (boost_shared, 2thread_10pct_write, 2, 0.10, false)
1508 BENCH_REL (pthrd_rwlock, 2thread_10pct_write, 2, 0.10, false)
1509 BENCHMARK_DRAW_LINE()
1510 BENCH_BASE(folly_rwspin, 4thread_10pct_write, 4, 0.10, false)
1511 BENCH_REL (shmtx_wr_pri, 4thread_10pct_write, 4, 0.10, false)
1512 BENCH_REL (shmtx_rd_pri, 4thread_10pct_write, 4, 0.10, false)
1513 BENCH_REL (folly_ticket, 4thread_10pct_write, 4, 0.10, false)
1514 BENCH_REL (boost_shared, 4thread_10pct_write, 4, 0.10, false)
1515 BENCH_REL (pthrd_rwlock, 4thread_10pct_write, 4, 0.10, false)
1516 BENCHMARK_DRAW_LINE()
1517 BENCH_BASE(folly_rwspin, 8thread_10pct_write, 8, 0.10, false)
1518 BENCH_REL (shmtx_wr_pri, 8thread_10pct_write, 8, 0.10, false)
1519 BENCH_REL (shmtx_rd_pri, 8thread_10pct_write, 8, 0.10, false)
1520 BENCH_REL (folly_ticket, 8thread_10pct_write, 8, 0.10, false)
1521 BENCH_REL (boost_shared, 8thread_10pct_write, 8, 0.10, false)
1522 BENCH_REL (pthrd_rwlock, 8thread_10pct_write, 8, 0.10, false)
1523 BENCHMARK_DRAW_LINE()
1524 BENCH_BASE(folly_rwspin, 16thread_10pct_write, 16, 0.10, false)
1525 BENCH_REL (shmtx_wr_pri, 16thread_10pct_write, 16, 0.10, false)
1526 BENCH_REL (shmtx_rd_pri, 16thread_10pct_write, 16, 0.10, false)
1527 BENCH_REL (folly_ticket, 16thread_10pct_write, 16, 0.10, false)
1528 BENCH_REL (boost_shared, 16thread_10pct_write, 16, 0.10, false)
1529 BENCH_REL (pthrd_rwlock, 16thread_10pct_write, 16, 0.10, false)
1530 BENCHMARK_DRAW_LINE()
1531 BENCH_BASE(folly_rwspin, 32thread_10pct_write, 32, 0.10, false)
1532 BENCH_REL (shmtx_wr_pri, 32thread_10pct_write, 32, 0.10, false)
1533 BENCH_REL (shmtx_rd_pri, 32thread_10pct_write, 32, 0.10, false)
1534 BENCH_REL (folly_ticket, 32thread_10pct_write, 32, 0.10, false)
1535 BENCH_REL (boost_shared, 32thread_10pct_write, 32, 0.10, false)
1536 BENCH_REL (pthrd_rwlock, 32thread_10pct_write, 32, 0.10, false)
1537 BENCHMARK_DRAW_LINE()
1538 BENCH_BASE(folly_rwspin, 64thread_10pct_write, 64, 0.10, false)
1539 BENCH_REL (shmtx_wr_pri, 64thread_10pct_write, 64, 0.10, false)
1540 BENCH_REL (shmtx_rd_pri, 64thread_10pct_write, 64, 0.10, false)
1541 BENCH_REL (folly_ticket, 64thread_10pct_write, 64, 0.10, false)
1542 BENCH_REL (boost_shared, 64thread_10pct_write, 64, 0.10, false)
1543 BENCH_REL (pthrd_rwlock, 64thread_10pct_write, 64, 0.10, false)
1545 // 1 lock used by everybody, 1% writes. This is a more realistic example
1546 // than the concurrent_*_reads benchmark, but still shows SharedMutex locks
1547 // winning over all of the others
1548 BENCHMARK_DRAW_LINE()
1549 BENCHMARK_DRAW_LINE()
1550 BENCH_BASE(folly_rwspin, 1thread_1pct_write, 1, 0.01, false)
1551 BENCH_REL (shmtx_wr_pri, 1thread_1pct_write, 1, 0.01, false)
1552 BENCH_REL (shmtx_w_bare, 1thread_1pct_write, 1, 0.01, false)
1553 BENCH_REL (shmtx_rd_pri, 1thread_1pct_write, 1, 0.01, false)
1554 BENCH_REL (shmtx_r_bare, 1thread_1pct_write, 1, 0.01, false)
1555 BENCH_REL (folly_ticket, 1thread_1pct_write, 1, 0.01, false)
1556 BENCH_REL (boost_shared, 1thread_1pct_write, 1, 0.01, false)
1557 BENCH_REL (pthrd_rwlock, 1thread_1pct_write, 1, 0.01, false)
1558 BENCHMARK_DRAW_LINE()
1559 BENCH_BASE(folly_rwspin, 2thread_1pct_write, 2, 0.01, false)
1560 BENCH_REL (shmtx_wr_pri, 2thread_1pct_write, 2, 0.01, false)
1561 BENCH_REL (shmtx_w_bare, 2thread_1pct_write, 2, 0.01, false)
1562 BENCH_REL (shmtx_rd_pri, 2thread_1pct_write, 2, 0.01, false)
1563 BENCH_REL (shmtx_r_bare, 2thread_1pct_write, 2, 0.01, false)
1564 BENCH_REL (folly_ticket, 2thread_1pct_write, 2, 0.01, false)
1565 BENCH_REL (boost_shared, 2thread_1pct_write, 2, 0.01, false)
1566 BENCH_REL (pthrd_rwlock, 2thread_1pct_write, 2, 0.01, false)
1567 BENCHMARK_DRAW_LINE()
1568 BENCH_BASE(folly_rwspin, 4thread_1pct_write, 4, 0.01, false)
1569 BENCH_REL (shmtx_wr_pri, 4thread_1pct_write, 4, 0.01, false)
1570 BENCH_REL (shmtx_w_bare, 4thread_1pct_write, 4, 0.01, false)
1571 BENCH_REL (shmtx_rd_pri, 4thread_1pct_write, 4, 0.01, false)
1572 BENCH_REL (shmtx_r_bare, 4thread_1pct_write, 4, 0.01, false)
1573 BENCH_REL (folly_ticket, 4thread_1pct_write, 4, 0.01, false)
1574 BENCH_REL (boost_shared, 4thread_1pct_write, 4, 0.01, false)
1575 BENCH_REL (pthrd_rwlock, 4thread_1pct_write, 4, 0.01, false)
1576 BENCHMARK_DRAW_LINE()
1577 BENCH_BASE(folly_rwspin, 8thread_1pct_write, 8, 0.01, false)
1578 BENCH_REL (shmtx_wr_pri, 8thread_1pct_write, 8, 0.01, false)
1579 BENCH_REL (shmtx_w_bare, 8thread_1pct_write, 8, 0.01, false)
1580 BENCH_REL (shmtx_rd_pri, 8thread_1pct_write, 8, 0.01, false)
1581 BENCH_REL (shmtx_r_bare, 8thread_1pct_write, 8, 0.01, false)
1582 BENCH_REL (folly_ticket, 8thread_1pct_write, 8, 0.01, false)
1583 BENCH_REL (boost_shared, 8thread_1pct_write, 8, 0.01, false)
1584 BENCH_REL (pthrd_rwlock, 8thread_1pct_write, 8, 0.01, false)
1585 BENCHMARK_DRAW_LINE()
1586 BENCH_BASE(folly_rwspin, 16thread_1pct_write, 16, 0.01, false)
1587 BENCH_REL (shmtx_wr_pri, 16thread_1pct_write, 16, 0.01, false)
1588 BENCH_REL (shmtx_w_bare, 16thread_1pct_write, 16, 0.01, false)
1589 BENCH_REL (shmtx_rd_pri, 16thread_1pct_write, 16, 0.01, false)
1590 BENCH_REL (shmtx_r_bare, 16thread_1pct_write, 16, 0.01, false)
1591 BENCH_REL (folly_ticket, 16thread_1pct_write, 16, 0.01, false)
1592 BENCH_REL (boost_shared, 16thread_1pct_write, 16, 0.01, false)
1593 BENCH_REL (pthrd_rwlock, 16thread_1pct_write, 16, 0.01, false)
1594 BENCHMARK_DRAW_LINE()
1595 BENCH_BASE(folly_rwspin, 32thread_1pct_write, 32, 0.01, false)
1596 BENCH_REL (shmtx_wr_pri, 32thread_1pct_write, 32, 0.01, false)
1597 BENCH_REL (shmtx_w_bare, 32thread_1pct_write, 32, 0.01, false)
1598 BENCH_REL (shmtx_rd_pri, 32thread_1pct_write, 32, 0.01, false)
1599 BENCH_REL (shmtx_r_bare, 32thread_1pct_write, 32, 0.01, false)
1600 BENCH_REL (folly_ticket, 32thread_1pct_write, 32, 0.01, false)
1601 BENCH_REL (boost_shared, 32thread_1pct_write, 32, 0.01, false)
1602 BENCH_REL (pthrd_rwlock, 32thread_1pct_write, 32, 0.01, false)
1603 BENCHMARK_DRAW_LINE()
1604 BENCH_BASE(folly_rwspin, 64thread_1pct_write, 64, 0.01, false)
1605 BENCH_REL (shmtx_wr_pri, 64thread_1pct_write, 64, 0.01, false)
1606 BENCH_REL (shmtx_w_bare, 64thread_1pct_write, 64, 0.01, false)
1607 BENCH_REL (shmtx_rd_pri, 64thread_1pct_write, 64, 0.01, false)
1608 BENCH_REL (shmtx_r_bare, 64thread_1pct_write, 64, 0.01, false)
1609 BENCH_REL (folly_ticket, 64thread_1pct_write, 64, 0.01, false)
1610 BENCH_REL (boost_shared, 64thread_1pct_write, 64, 0.01, false)
1611 BENCH_REL (pthrd_rwlock, 64thread_1pct_write, 64, 0.01, false)
1613 // Worst case scenario for deferred locks. No actual sharing, likely that
1614 // read operations will have to first set the kDeferredReadersPossibleBit,
1615 // and likely that writers will have to scan deferredReaders[].
1616 BENCHMARK_DRAW_LINE()
1617 BENCH_BASE(folly_rwspin, 2thr_2lock_50pct_write, 2, 0.50, true)
1618 BENCH_REL (shmtx_wr_pri, 2thr_2lock_50pct_write, 2, 0.50, true)
1619 BENCH_REL (shmtx_rd_pri, 2thr_2lock_50pct_write, 2, 0.50, true)
1620 BENCH_BASE(folly_rwspin, 4thr_4lock_50pct_write, 4, 0.50, true)
1621 BENCH_REL (shmtx_wr_pri, 4thr_4lock_50pct_write, 4, 0.50, true)
1622 BENCH_REL (shmtx_rd_pri, 4thr_4lock_50pct_write, 4, 0.50, true)
1623 BENCH_BASE(folly_rwspin, 8thr_8lock_50pct_write, 8, 0.50, true)
1624 BENCH_REL (shmtx_wr_pri, 8thr_8lock_50pct_write, 8, 0.50, true)
1625 BENCH_REL (shmtx_rd_pri, 8thr_8lock_50pct_write, 8, 0.50, true)
1626 BENCH_BASE(folly_rwspin, 16thr_16lock_50pct_write, 16, 0.50, true)
1627 BENCH_REL (shmtx_wr_pri, 16thr_16lock_50pct_write, 16, 0.50, true)
1628 BENCH_REL (shmtx_rd_pri, 16thr_16lock_50pct_write, 16, 0.50, true)
1629 BENCH_BASE(folly_rwspin, 32thr_32lock_50pct_write, 32, 0.50, true)
1630 BENCH_REL (shmtx_wr_pri, 32thr_32lock_50pct_write, 32, 0.50, true)
1631 BENCH_REL (shmtx_rd_pri, 32thr_32lock_50pct_write, 32, 0.50, true)
1632 BENCH_BASE(folly_rwspin, 64thr_64lock_50pct_write, 64, 0.50, true)
1633 BENCH_REL (shmtx_wr_pri, 64thr_64lock_50pct_write, 64, 0.50, true)
1634 BENCH_REL (shmtx_rd_pri, 64thr_64lock_50pct_write, 64, 0.50, true)
1635 BENCHMARK_DRAW_LINE()
1636 BENCH_BASE(folly_rwspin, 2thr_2lock_10pct_write, 2, 0.10, true)
1637 BENCH_REL (shmtx_wr_pri, 2thr_2lock_10pct_write, 2, 0.10, true)
1638 BENCH_REL (shmtx_rd_pri, 2thr_2lock_10pct_write, 2, 0.10, true)
1639 BENCH_BASE(folly_rwspin, 4thr_4lock_10pct_write, 4, 0.10, true)
1640 BENCH_REL (shmtx_wr_pri, 4thr_4lock_10pct_write, 4, 0.10, true)
1641 BENCH_REL (shmtx_rd_pri, 4thr_4lock_10pct_write, 4, 0.10, true)
1642 BENCH_BASE(folly_rwspin, 8thr_8lock_10pct_write, 8, 0.10, true)
1643 BENCH_REL (shmtx_wr_pri, 8thr_8lock_10pct_write, 8, 0.10, true)
1644 BENCH_REL (shmtx_rd_pri, 8thr_8lock_10pct_write, 8, 0.10, true)
1645 BENCH_BASE(folly_rwspin, 16thr_16lock_10pct_write, 16, 0.10, true)
1646 BENCH_REL (shmtx_wr_pri, 16thr_16lock_10pct_write, 16, 0.10, true)
1647 BENCH_REL (shmtx_rd_pri, 16thr_16lock_10pct_write, 16, 0.10, true)
1648 BENCH_BASE(folly_rwspin, 32thr_32lock_10pct_write, 32, 0.10, true)
1649 BENCH_REL (shmtx_wr_pri, 32thr_32lock_10pct_write, 32, 0.10, true)
1650 BENCH_REL (shmtx_rd_pri, 32thr_32lock_10pct_write, 32, 0.10, true)
1651 BENCH_BASE(folly_rwspin, 64thr_64lock_10pct_write, 64, 0.10, true)
1652 BENCH_REL (shmtx_wr_pri, 64thr_64lock_10pct_write, 64, 0.10, true)
1653 BENCH_REL (shmtx_rd_pri, 64thr_64lock_10pct_write, 64, 0.10, true)
1654 BENCHMARK_DRAW_LINE()
1655 BENCH_BASE(folly_rwspin, 2thr_2lock_1pct_write, 2, 0.01, true)
1656 BENCH_REL (shmtx_wr_pri, 2thr_2lock_1pct_write, 2, 0.01, true)
1657 BENCH_REL (shmtx_rd_pri, 2thr_2lock_1pct_write, 2, 0.01, true)
1658 BENCH_BASE(folly_rwspin, 4thr_4lock_1pct_write, 4, 0.01, true)
1659 BENCH_REL (shmtx_wr_pri, 4thr_4lock_1pct_write, 4, 0.01, true)
1660 BENCH_REL (shmtx_rd_pri, 4thr_4lock_1pct_write, 4, 0.01, true)
1661 BENCH_BASE(folly_rwspin, 8thr_8lock_1pct_write, 8, 0.01, true)
1662 BENCH_REL (shmtx_wr_pri, 8thr_8lock_1pct_write, 8, 0.01, true)
1663 BENCH_REL (shmtx_rd_pri, 8thr_8lock_1pct_write, 8, 0.01, true)
1664 BENCH_BASE(folly_rwspin, 16thr_16lock_1pct_write, 16, 0.01, true)
1665 BENCH_REL (shmtx_wr_pri, 16thr_16lock_1pct_write, 16, 0.01, true)
1666 BENCH_REL (shmtx_rd_pri, 16thr_16lock_1pct_write, 16, 0.01, true)
1667 BENCH_BASE(folly_rwspin, 32thr_32lock_1pct_write, 32, 0.01, true)
1668 BENCH_REL (shmtx_wr_pri, 32thr_32lock_1pct_write, 32, 0.01, true)
1669 BENCH_REL (shmtx_rd_pri, 32thr_32lock_1pct_write, 32, 0.01, true)
1670 BENCH_BASE(folly_rwspin, 64thr_64lock_1pct_write, 64, 0.01, true)
1671 BENCH_REL (shmtx_wr_pri, 64thr_64lock_1pct_write, 64, 0.01, true)
1672 BENCH_REL (shmtx_rd_pri, 64thr_64lock_1pct_write, 64, 0.01, true)
1674 // Ping-pong tests have a scaled number of iterations, because their burn
1675 // loop would make them too slow otherwise. Ping-pong with burn count of
1676 // 100k or 300k shows the advantage of soft-spin, reducing the cost of
1677 // each wakeup by about 20 usec. (Take benchmark reported difference,
1678 // ~400 nanos, multiply by the scale of 100, then divide by 2 because
1679 // each round has two wakeups.)
1680 BENCHMARK_DRAW_LINE()
1681 BENCHMARK_DRAW_LINE()
1682 BENCH_BASE(folly_rwspin_ping_pong, burn0, 1, 0)
1683 BENCH_REL (shmtx_w_bare_ping_pong, burn0, 1, 0)
1684 BENCH_REL (shmtx_r_bare_ping_pong, burn0, 1, 0)
1685 BENCH_REL (folly_ticket_ping_pong, burn0, 1, 0)
1686 BENCH_REL (boost_shared_ping_pong, burn0, 1, 0)
1687 BENCH_REL (pthrd_rwlock_ping_pong, burn0, 1, 0)
1688 BENCHMARK_DRAW_LINE()
1689 BENCH_BASE(folly_rwspin_ping_pong, burn100k, 100, 100000)
1690 BENCH_REL (shmtx_w_bare_ping_pong, burn100k, 100, 100000)
1691 BENCH_REL (shmtx_r_bare_ping_pong, burn100k, 100, 100000)
1692 BENCH_REL (folly_ticket_ping_pong, burn100k, 100, 100000)
1693 BENCH_REL (boost_shared_ping_pong, burn100k, 100, 100000)
1694 BENCH_REL (pthrd_rwlock_ping_pong, burn100k, 100, 100000)
1695 BENCHMARK_DRAW_LINE()
1696 BENCH_BASE(folly_rwspin_ping_pong, burn300k, 100, 300000)
1697 BENCH_REL (shmtx_w_bare_ping_pong, burn300k, 100, 300000)
1698 BENCH_REL (shmtx_r_bare_ping_pong, burn300k, 100, 300000)
1699 BENCH_REL (folly_ticket_ping_pong, burn300k, 100, 300000)
1700 BENCH_REL (boost_shared_ping_pong, burn300k, 100, 300000)
1701 BENCH_REL (pthrd_rwlock_ping_pong, burn300k, 100, 300000)
1702 BENCHMARK_DRAW_LINE()
1703 BENCH_BASE(folly_rwspin_ping_pong, burn1M, 1000, 1000000)
1704 BENCH_REL (shmtx_w_bare_ping_pong, burn1M, 1000, 1000000)
1705 BENCH_REL (shmtx_r_bare_ping_pong, burn1M, 1000, 1000000)
1706 BENCH_REL (folly_ticket_ping_pong, burn1M, 1000, 1000000)
1707 BENCH_REL (boost_shared_ping_pong, burn1M, 1000, 1000000)
1708 BENCH_REL (pthrd_rwlock_ping_pong, burn1M, 1000, 1000000)
1710 // Reproduce with 10 minutes and
1712 // shared_mutex_test --benchmark --bm_min_iters=1000000
1714 // Comparison use folly::RWSpinLock as the baseline, with the
1715 // following row being the default SharedMutex (using *Holder or
1716 // Token-ful methods).
1717 // ============================================================================
1718 // folly/experimental/test/SharedMutexTest.cpp relative time/iter iters/s
1719 // ============================================================================
1720 // single_thread_lock_shared_unlock_shared 22.78ns 43.89M
1721 // single_thread_lock_unlock 26.01ns 38.45M
1722 // ----------------------------------------------------------------------------
1723 // ----------------------------------------------------------------------------
1724 // folly_rwspin_reads(1thread) 15.09ns 66.25M
1725 // shmtx_wr_pri_reads(1thread) 69.89% 21.60ns 46.30M
1726 // shmtx_w_bare_reads(1thread) 58.25% 25.91ns 38.59M
1727 // shmtx_rd_pri_reads(1thread) 72.50% 20.82ns 48.03M
1728 // shmtx_r_bare_reads(1thread) 58.27% 25.91ns 38.60M
1729 // folly_ticket_reads(1thread) 54.80% 27.55ns 36.30M
1730 // boost_shared_reads(1thread) 10.88% 138.80ns 7.20M
1731 // pthrd_rwlock_reads(1thread) 40.68% 37.11ns 26.95M
1732 // ----------------------------------------------------------------------------
1733 // folly_rwspin_reads(2thread) 92.63ns 10.80M
1734 // shmtx_wr_pri_reads(2thread) 462.86% 20.01ns 49.97M
1735 // shmtx_w_bare_reads(2thread) 430.53% 21.51ns 46.48M
1736 // shmtx_rd_pri_reads(2thread) 487.13% 19.01ns 52.59M
1737 // shmtx_r_bare_reads(2thread) 433.35% 21.37ns 46.79M
1738 // folly_ticket_reads(2thread) 69.82% 132.67ns 7.54M
1739 // boost_shared_reads(2thread) 36.66% 252.63ns 3.96M
1740 // pthrd_rwlock_reads(2thread) 127.76% 72.50ns 13.79M
1741 // ----------------------------------------------------------------------------
1742 // folly_rwspin_reads(4thread) 97.45ns 10.26M
1743 // shmtx_wr_pri_reads(4thread) 978.22% 9.96ns 100.38M
1744 // shmtx_w_bare_reads(4thread) 908.35% 10.73ns 93.21M
1745 // shmtx_rd_pri_reads(4thread) 1032.29% 9.44ns 105.93M
1746 // shmtx_r_bare_reads(4thread) 912.38% 10.68ns 93.63M
1747 // folly_ticket_reads(4thread) 46.08% 211.46ns 4.73M
1748 // boost_shared_reads(4thread) 25.00% 389.74ns 2.57M
1749 // pthrd_rwlock_reads(4thread) 47.53% 205.01ns 4.88M
1750 // ----------------------------------------------------------------------------
1751 // folly_rwspin_reads(8thread) 147.24ns 6.79M
1752 // shmtx_wr_pri_reads(8thread) 2915.66% 5.05ns 198.02M
1753 // shmtx_w_bare_reads(8thread) 2699.32% 5.45ns 183.32M
1754 // shmtx_rd_pri_reads(8thread) 3092.58% 4.76ns 210.03M
1755 // shmtx_r_bare_reads(8thread) 2744.63% 5.36ns 186.40M
1756 // folly_ticket_reads(8thread) 54.84% 268.47ns 3.72M
1757 // boost_shared_reads(8thread) 42.40% 347.30ns 2.88M
1758 // pthrd_rwlock_reads(8thread) 78.90% 186.63ns 5.36M
1759 // ----------------------------------------------------------------------------
1760 // folly_rwspin_reads(16thread) 166.25ns 6.02M
1761 // shmtx_wr_pri_reads(16thread) 6133.03% 2.71ns 368.91M
1762 // shmtx_w_bare_reads(16thread) 5936.05% 2.80ns 357.06M
1763 // shmtx_rd_pri_reads(16thread) 6786.57% 2.45ns 408.22M
1764 // shmtx_r_bare_reads(16thread) 5995.54% 2.77ns 360.64M
1765 // folly_ticket_reads(16thread) 56.35% 295.01ns 3.39M
1766 // boost_shared_reads(16thread) 51.62% 322.08ns 3.10M
1767 // pthrd_rwlock_reads(16thread) 92.47% 179.79ns 5.56M
1768 // ----------------------------------------------------------------------------
1769 // folly_rwspin_reads(32thread) 107.72ns 9.28M
1770 // shmtx_wr_pri_reads(32thread) 6772.80% 1.59ns 628.77M
1771 // shmtx_w_bare_reads(32thread) 6236.13% 1.73ns 578.94M
1772 // shmtx_rd_pri_reads(32thread) 8143.32% 1.32ns 756.00M
1773 // shmtx_r_bare_reads(32thread) 6485.18% 1.66ns 602.06M
1774 // folly_ticket_reads(32thread) 35.12% 306.73ns 3.26M
1775 // boost_shared_reads(32thread) 28.19% 382.17ns 2.62M
1776 // pthrd_rwlock_reads(32thread) 65.29% 164.99ns 6.06M
1777 // ----------------------------------------------------------------------------
1778 // folly_rwspin_reads(64thread) 119.46ns 8.37M
1779 // shmtx_wr_pri_reads(64thread) 6744.92% 1.77ns 564.60M
1780 // shmtx_w_bare_reads(64thread) 6268.50% 1.91ns 524.72M
1781 // shmtx_rd_pri_reads(64thread) 7508.56% 1.59ns 628.52M
1782 // shmtx_r_bare_reads(64thread) 6299.53% 1.90ns 527.32M
1783 // folly_ticket_reads(64thread) 37.42% 319.26ns 3.13M
1784 // boost_shared_reads(64thread) 32.58% 366.70ns 2.73M
1785 // pthrd_rwlock_reads(64thread) 73.64% 162.24ns 6.16M
1786 // ----------------------------------------------------------------------------
1787 // ----------------------------------------------------------------------------
1788 // folly_rwspin(1thread_all_write) 25.51ns 39.19M
1789 // shmtx_wr_pri(1thread_all_write) 97.38% 26.20ns 38.17M
1790 // shmtx_rd_pri(1thread_all_write) 97.55% 26.16ns 38.23M
1791 // folly_ticket(1thread_all_write) 90.98% 28.04ns 35.66M
1792 // boost_shared(1thread_all_write) 16.80% 151.89ns 6.58M
1793 // pthrd_rwlock(1thread_all_write) 63.86% 39.96ns 25.03M
1794 // pthrd_mutex_(1thread_all_write) 82.05% 31.09ns 32.16M
1795 // ----------------------------------------------------------------------------
1796 // folly_rwspin(2thread_all_write) 100.70ns 9.93M
1797 // shmtx_wr_pri(2thread_all_write) 40.83% 246.61ns 4.05M
1798 // shmtx_rd_pri(2thread_all_write) 40.53% 248.44ns 4.03M
1799 // folly_ticket(2thread_all_write) 58.49% 172.17ns 5.81M
1800 // boost_shared(2thread_all_write) 24.26% 415.00ns 2.41M
1801 // pthrd_rwlock(2thread_all_write) 41.35% 243.49ns 4.11M
1802 // pthrd_mutex_(2thread_all_write) 146.91% 68.55ns 14.59M
1803 // ----------------------------------------------------------------------------
1804 // folly_rwspin(4thread_all_write) 199.52ns 5.01M
1805 // shmtx_wr_pri(4thread_all_write) 51.71% 385.86ns 2.59M
1806 // shmtx_rd_pri(4thread_all_write) 49.43% 403.62ns 2.48M
1807 // folly_ticket(4thread_all_write) 117.88% 169.26ns 5.91M
1808 // boost_shared(4thread_all_write) 9.81% 2.03us 491.48K
1809 // pthrd_rwlock(4thread_all_write) 28.23% 706.69ns 1.42M
1810 // pthrd_mutex_(4thread_all_write) 111.54% 178.88ns 5.59M
1811 // ----------------------------------------------------------------------------
1812 // folly_rwspin(8thread_all_write) 304.61ns 3.28M
1813 // shmtx_wr_pri(8thread_all_write) 69.77% 436.59ns 2.29M
1814 // shmtx_rd_pri(8thread_all_write) 66.58% 457.51ns 2.19M
1815 // folly_ticket(8thread_all_write) 141.00% 216.03ns 4.63M
1816 // boost_shared(8thread_all_write) 6.11% 4.99us 200.59K
1817 // pthrd_rwlock(8thread_all_write) 38.03% 800.88ns 1.25M
1818 // pthrd_mutex_(8thread_all_write) 177.66% 171.45ns 5.83M
1819 // ----------------------------------------------------------------------------
1820 // folly_rwspin(16thread_all_write) 576.97ns 1.73M
1821 // shmtx_wr_pri(16thread_all_write) 105.72% 545.77ns 1.83M
1822 // shmtx_rd_pri(16thread_all_write) 105.13% 548.83ns 1.82M
1823 // folly_ticket(16thread_all_write) 161.70% 356.82ns 2.80M
1824 // boost_shared(16thread_all_write) 7.73% 7.46us 134.03K
1825 // pthrd_rwlock(16thread_all_write) 96.88% 595.54ns 1.68M
1826 // pthrd_mutex_(16thread_all_write) 330.44% 174.61ns 5.73M
1827 // ----------------------------------------------------------------------------
1828 // folly_rwspin(32thread_all_write) 1.41us 707.76K
1829 // shmtx_wr_pri(32thread_all_write) 240.46% 587.58ns 1.70M
1830 // shmtx_rd_pri(32thread_all_write) 393.71% 358.87ns 2.79M
1831 // folly_ticket(32thread_all_write) 325.07% 434.65ns 2.30M
1832 // boost_shared(32thread_all_write) 18.57% 7.61us 131.43K
1833 // pthrd_rwlock(32thread_all_write) 266.78% 529.62ns 1.89M
1834 // pthrd_mutex_(32thread_all_write) 877.89% 160.94ns 6.21M
1835 // ----------------------------------------------------------------------------
1836 // folly_rwspin(64thread_all_write) 1.76us 566.94K
1837 // shmtx_wr_pri(64thread_all_write) 255.67% 689.91ns 1.45M
1838 // shmtx_rd_pri(64thread_all_write) 468.82% 376.23ns 2.66M
1839 // folly_ticket(64thread_all_write) 294.72% 598.49ns 1.67M
1840 // boost_shared(64thread_all_write) 23.39% 7.54us 132.58K
1841 // pthrd_rwlock(64thread_all_write) 321.39% 548.83ns 1.82M
1842 // pthrd_mutex_(64thread_all_write) 1165.04% 151.40ns 6.61M
1843 // ----------------------------------------------------------------------------
1844 // ----------------------------------------------------------------------------
1845 // folly_rwspin(1thread_10pct_write) 19.51ns 51.26M
1846 // shmtx_wr_pri(1thread_10pct_write) 83.25% 23.43ns 42.67M
1847 // shmtx_rd_pri(1thread_10pct_write) 83.31% 23.42ns 42.71M
1848 // folly_ticket(1thread_10pct_write) 70.88% 27.52ns 36.34M
1849 // boost_shared(1thread_10pct_write) 13.09% 148.99ns 6.71M
1850 // pthrd_rwlock(1thread_10pct_write) 47.41% 41.15ns 24.30M
1851 // ----------------------------------------------------------------------------
1852 // folly_rwspin(2thread_10pct_write) 159.42ns 6.27M
1853 // shmtx_wr_pri(2thread_10pct_write) 188.44% 84.60ns 11.82M
1854 // shmtx_rd_pri(2thread_10pct_write) 188.29% 84.67ns 11.81M
1855 // folly_ticket(2thread_10pct_write) 140.28% 113.64ns 8.80M
1856 // boost_shared(2thread_10pct_write) 42.09% 378.81ns 2.64M
1857 // pthrd_rwlock(2thread_10pct_write) 103.86% 153.49ns 6.51M
1858 // ----------------------------------------------------------------------------
1859 // folly_rwspin(4thread_10pct_write) 193.35ns 5.17M
1860 // shmtx_wr_pri(4thread_10pct_write) 184.30% 104.91ns 9.53M
1861 // shmtx_rd_pri(4thread_10pct_write) 163.76% 118.07ns 8.47M
1862 // folly_ticket(4thread_10pct_write) 124.07% 155.84ns 6.42M
1863 // boost_shared(4thread_10pct_write) 16.32% 1.18us 843.92K
1864 // pthrd_rwlock(4thread_10pct_write) 48.59% 397.94ns 2.51M
1865 // ----------------------------------------------------------------------------
1866 // folly_rwspin(8thread_10pct_write) 373.17ns 2.68M
1867 // shmtx_wr_pri(8thread_10pct_write) 252.02% 148.08ns 6.75M
1868 // shmtx_rd_pri(8thread_10pct_write) 203.59% 183.30ns 5.46M
1869 // folly_ticket(8thread_10pct_write) 184.37% 202.40ns 4.94M
1870 // boost_shared(8thread_10pct_write) 15.85% 2.35us 424.72K
1871 // pthrd_rwlock(8thread_10pct_write) 83.03% 449.45ns 2.22M
1872 // ----------------------------------------------------------------------------
1873 // folly_rwspin(16thread_10pct_write) 742.87ns 1.35M
1874 // shmtx_wr_pri(16thread_10pct_write) 344.27% 215.78ns 4.63M
1875 // shmtx_rd_pri(16thread_10pct_write) 287.04% 258.80ns 3.86M
1876 // folly_ticket(16thread_10pct_write) 277.25% 267.94ns 3.73M
1877 // boost_shared(16thread_10pct_write) 15.33% 4.85us 206.30K
1878 // pthrd_rwlock(16thread_10pct_write) 158.34% 469.16ns 2.13M
1879 // ----------------------------------------------------------------------------
1880 // folly_rwspin(32thread_10pct_write) 799.97ns 1.25M
1881 // shmtx_wr_pri(32thread_10pct_write) 351.40% 227.65ns 4.39M
1882 // shmtx_rd_pri(32thread_10pct_write) 341.71% 234.11ns 4.27M
1883 // folly_ticket(32thread_10pct_write) 245.91% 325.31ns 3.07M
1884 // boost_shared(32thread_10pct_write) 7.72% 10.36us 96.56K
1885 // pthrd_rwlock(32thread_10pct_write) 165.87% 482.30ns 2.07M
1886 // ----------------------------------------------------------------------------
1887 // folly_rwspin(64thread_10pct_write) 1.12us 892.01K
1888 // shmtx_wr_pri(64thread_10pct_write) 429.84% 260.81ns 3.83M
1889 // shmtx_rd_pri(64thread_10pct_write) 456.93% 245.35ns 4.08M
1890 // folly_ticket(64thread_10pct_write) 219.21% 511.42ns 1.96M
1891 // boost_shared(64thread_10pct_write) 5.43% 20.65us 48.44K
1892 // pthrd_rwlock(64thread_10pct_write) 233.93% 479.23ns 2.09M
1893 // ----------------------------------------------------------------------------
1894 // ----------------------------------------------------------------------------
1895 // folly_rwspin(1thread_1pct_write) 18.88ns 52.98M
1896 // shmtx_wr_pri(1thread_1pct_write) 81.53% 23.15ns 43.19M
1897 // shmtx_w_bare(1thread_1pct_write) 67.90% 27.80ns 35.97M
1898 // shmtx_rd_pri(1thread_1pct_write) 81.50% 23.16ns 43.18M
1899 // shmtx_r_bare(1thread_1pct_write) 67.74% 27.86ns 35.89M
1900 // folly_ticket(1thread_1pct_write) 68.68% 27.48ns 36.39M
1901 // boost_shared(1thread_1pct_write) 12.80% 147.51ns 6.78M
1902 // pthrd_rwlock(1thread_1pct_write) 45.81% 41.20ns 24.27M
1903 // ----------------------------------------------------------------------------
1904 // folly_rwspin(2thread_1pct_write) 125.85ns 7.95M
1905 // shmtx_wr_pri(2thread_1pct_write) 359.04% 35.05ns 28.53M
1906 // shmtx_w_bare(2thread_1pct_write) 475.60% 26.46ns 37.79M
1907 // shmtx_rd_pri(2thread_1pct_write) 332.75% 37.82ns 26.44M
1908 // shmtx_r_bare(2thread_1pct_write) 115.64% 108.83ns 9.19M
1909 // folly_ticket(2thread_1pct_write) 140.24% 89.74ns 11.14M
1910 // boost_shared(2thread_1pct_write) 40.62% 309.82ns 3.23M
1911 // pthrd_rwlock(2thread_1pct_write) 134.67% 93.45ns 10.70M
1912 // ----------------------------------------------------------------------------
1913 // folly_rwspin(4thread_1pct_write) 126.70ns 7.89M
1914 // shmtx_wr_pri(4thread_1pct_write) 422.20% 30.01ns 33.32M
1915 // shmtx_w_bare(4thread_1pct_write) 403.52% 31.40ns 31.85M
1916 // shmtx_rd_pri(4thread_1pct_write) 282.50% 44.85ns 22.30M
1917 // shmtx_r_bare(4thread_1pct_write) 66.30% 191.10ns 5.23M
1918 // folly_ticket(4thread_1pct_write) 91.93% 137.83ns 7.26M
1919 // boost_shared(4thread_1pct_write) 22.74% 557.10ns 1.80M
1920 // pthrd_rwlock(4thread_1pct_write) 55.66% 227.62ns 4.39M
1921 // ----------------------------------------------------------------------------
1922 // folly_rwspin(8thread_1pct_write) 169.42ns 5.90M
1923 // shmtx_wr_pri(8thread_1pct_write) 567.81% 29.84ns 33.51M
1924 // shmtx_w_bare(8thread_1pct_write) 519.18% 32.63ns 30.64M
1925 // shmtx_rd_pri(8thread_1pct_write) 172.36% 98.30ns 10.17M
1926 // shmtx_r_bare(8thread_1pct_write) 75.56% 224.21ns 4.46M
1927 // folly_ticket(8thread_1pct_write) 104.03% 162.85ns 6.14M
1928 // boost_shared(8thread_1pct_write) 22.01% 769.73ns 1.30M
1929 // pthrd_rwlock(8thread_1pct_write) 71.79% 235.99ns 4.24M
1930 // ----------------------------------------------------------------------------
1931 // folly_rwspin(16thread_1pct_write) 385.88ns 2.59M
1932 // shmtx_wr_pri(16thread_1pct_write) 1039.03% 37.14ns 26.93M
1933 // shmtx_w_bare(16thread_1pct_write) 997.26% 38.69ns 25.84M
1934 // shmtx_rd_pri(16thread_1pct_write) 263.60% 146.39ns 6.83M
1935 // shmtx_r_bare(16thread_1pct_write) 173.16% 222.85ns 4.49M
1936 // folly_ticket(16thread_1pct_write) 179.37% 215.13ns 4.65M
1937 // boost_shared(16thread_1pct_write) 26.95% 1.43us 698.42K
1938 // pthrd_rwlock(16thread_1pct_write) 166.70% 231.48ns 4.32M
1939 // ----------------------------------------------------------------------------
1940 // folly_rwspin(32thread_1pct_write) 382.49ns 2.61M
1941 // shmtx_wr_pri(32thread_1pct_write) 1046.64% 36.54ns 27.36M
1942 // shmtx_w_bare(32thread_1pct_write) 922.87% 41.45ns 24.13M
1943 // shmtx_rd_pri(32thread_1pct_write) 251.93% 151.82ns 6.59M
1944 // shmtx_r_bare(32thread_1pct_write) 176.44% 216.78ns 4.61M
1945 // folly_ticket(32thread_1pct_write) 131.07% 291.82ns 3.43M
1946 // boost_shared(32thread_1pct_write) 12.77% 2.99us 333.95K
1947 // pthrd_rwlock(32thread_1pct_write) 173.43% 220.55ns 4.53M
1948 // ----------------------------------------------------------------------------
1949 // folly_rwspin(64thread_1pct_write) 510.54ns 1.96M
1950 // shmtx_wr_pri(64thread_1pct_write) 1378.27% 37.04ns 27.00M
1951 // shmtx_w_bare(64thread_1pct_write) 1178.24% 43.33ns 23.08M
1952 // shmtx_rd_pri(64thread_1pct_write) 325.29% 156.95ns 6.37M
1953 // shmtx_r_bare(64thread_1pct_write) 247.82% 206.02ns 4.85M
1954 // folly_ticket(64thread_1pct_write) 117.87% 433.13ns 2.31M
1955 // boost_shared(64thread_1pct_write) 9.45% 5.40us 185.09K
1956 // pthrd_rwlock(64thread_1pct_write) 236.72% 215.68ns 4.64M
1957 // ----------------------------------------------------------------------------
1958 // folly_rwspin(2thr_2lock_50pct_write) 10.85ns 92.15M
1959 // shmtx_wr_pri(2thr_2lock_50pct_write) 81.73% 13.28ns 75.32M
1960 // shmtx_rd_pri(2thr_2lock_50pct_write) 81.82% 13.26ns 75.40M
1961 // folly_rwspin(4thr_4lock_50pct_write) 5.29ns 188.90M
1962 // shmtx_wr_pri(4thr_4lock_50pct_write) 80.89% 6.54ns 152.80M
1963 // shmtx_rd_pri(4thr_4lock_50pct_write) 81.07% 6.53ns 153.14M
1964 // folly_rwspin(8thr_8lock_50pct_write) 2.63ns 380.57M
1965 // shmtx_wr_pri(8thr_8lock_50pct_write) 80.56% 3.26ns 306.57M
1966 // shmtx_rd_pri(8thr_8lock_50pct_write) 80.29% 3.27ns 305.54M
1967 // folly_rwspin(16thr_16lock_50pct_write) 1.31ns 764.70M
1968 // shmtx_wr_pri(16thr_16lock_50pct_write) 79.32% 1.65ns 606.54M
1969 // shmtx_rd_pri(16thr_16lock_50pct_write) 79.62% 1.64ns 608.84M
1970 // folly_rwspin(32thr_32lock_50pct_write) 1.20ns 836.75M
1971 // shmtx_wr_pri(32thr_32lock_50pct_write) 91.67% 1.30ns 767.07M
1972 // shmtx_rd_pri(32thr_32lock_50pct_write) 92.00% 1.30ns 769.82M
1973 // folly_rwspin(64thr_64lock_50pct_write) 1.39ns 717.80M
1974 // shmtx_wr_pri(64thr_64lock_50pct_write) 93.21% 1.49ns 669.08M
1975 // shmtx_rd_pri(64thr_64lock_50pct_write) 92.49% 1.51ns 663.89M
1976 // ----------------------------------------------------------------------------
1977 // folly_rwspin(2thr_2lock_10pct_write) 10.24ns 97.70M
1978 // shmtx_wr_pri(2thr_2lock_10pct_write) 76.46% 13.39ns 74.70M
1979 // shmtx_rd_pri(2thr_2lock_10pct_write) 76.35% 13.41ns 74.60M
1980 // folly_rwspin(4thr_4lock_10pct_write) 5.02ns 199.03M
1981 // shmtx_wr_pri(4thr_4lock_10pct_write) 75.83% 6.63ns 150.91M
1982 // shmtx_rd_pri(4thr_4lock_10pct_write) 76.10% 6.60ns 151.46M
1983 // folly_rwspin(8thr_8lock_10pct_write) 2.47ns 405.50M
1984 // shmtx_wr_pri(8thr_8lock_10pct_write) 74.54% 3.31ns 302.27M
1985 // shmtx_rd_pri(8thr_8lock_10pct_write) 74.85% 3.29ns 303.52M
1986 // folly_rwspin(16thr_16lock_10pct_write) 1.22ns 818.68M
1987 // shmtx_wr_pri(16thr_16lock_10pct_write) 73.35% 1.67ns 600.47M
1988 // shmtx_rd_pri(16thr_16lock_10pct_write) 73.38% 1.66ns 600.73M
1989 // folly_rwspin(32thr_32lock_10pct_write) 1.21ns 827.95M
1990 // shmtx_wr_pri(32thr_32lock_10pct_write) 96.13% 1.26ns 795.89M
1991 // shmtx_rd_pri(32thr_32lock_10pct_write) 96.01% 1.26ns 794.95M
1992 // folly_rwspin(64thr_64lock_10pct_write) 1.40ns 716.17M
1993 // shmtx_wr_pri(64thr_64lock_10pct_write) 96.91% 1.44ns 694.03M
1994 // shmtx_rd_pri(64thr_64lock_10pct_write) 96.85% 1.44ns 693.64M
1995 // ----------------------------------------------------------------------------
1996 // folly_rwspin(2thr_2lock_1pct_write) 10.11ns 98.91M
1997 // shmtx_wr_pri(2thr_2lock_1pct_write) 75.07% 13.47ns 74.25M
1998 // shmtx_rd_pri(2thr_2lock_1pct_write) 74.98% 13.48ns 74.16M
1999 // folly_rwspin(4thr_4lock_1pct_write) 4.96ns 201.77M
2000 // shmtx_wr_pri(4thr_4lock_1pct_write) 74.59% 6.64ns 150.49M
2001 // shmtx_rd_pri(4thr_4lock_1pct_write) 74.60% 6.64ns 150.51M
2002 // folly_rwspin(8thr_8lock_1pct_write) 2.44ns 410.42M
2003 // shmtx_wr_pri(8thr_8lock_1pct_write) 73.68% 3.31ns 302.41M
2004 // shmtx_rd_pri(8thr_8lock_1pct_write) 73.38% 3.32ns 301.16M
2005 // folly_rwspin(16thr_16lock_1pct_write) 1.21ns 827.53M
2006 // shmtx_wr_pri(16thr_16lock_1pct_write) 72.11% 1.68ns 596.74M
2007 // shmtx_rd_pri(16thr_16lock_1pct_write) 72.23% 1.67ns 597.73M
2008 // folly_rwspin(32thr_32lock_1pct_write) 1.22ns 819.53M
2009 // shmtx_wr_pri(32thr_32lock_1pct_write) 98.17% 1.24ns 804.50M
2010 // shmtx_rd_pri(32thr_32lock_1pct_write) 98.21% 1.24ns 804.86M
2011 // folly_rwspin(64thr_64lock_1pct_write) 1.41ns 710.26M
2012 // shmtx_wr_pri(64thr_64lock_1pct_write) 97.81% 1.44ns 694.71M
2013 // shmtx_rd_pri(64thr_64lock_1pct_write) 99.44% 1.42ns 706.28M
2014 // ----------------------------------------------------------------------------
2015 // ----------------------------------------------------------------------------
2016 // folly_rwspin_ping_pong(burn0) 641.24ns 1.56M
2017 // shmtx_w_bare_ping_pong(burn0) 91.07% 704.12ns 1.42M
2018 // shmtx_r_bare_ping_pong(burn0) 78.70% 814.84ns 1.23M
2019 // folly_ticket_ping_pong(burn0) 85.67% 748.53ns 1.34M
2020 // boost_shared_ping_pong(burn0) 5.58% 11.50us 86.96K
2021 // pthrd_rwlock_ping_pong(burn0) 8.81% 7.28us 137.40K
2022 // ----------------------------------------------------------------------------
2023 // folly_rwspin_ping_pong(burn100k) 678.97ns 1.47M
2024 // shmtx_w_bare_ping_pong(burn100k) 99.73% 680.78ns 1.47M
2025 // shmtx_r_bare_ping_pong(burn100k) 98.67% 688.13ns 1.45M
2026 // folly_ticket_ping_pong(burn100k) 99.31% 683.68ns 1.46M
2027 // boost_shared_ping_pong(burn100k) 58.23% 1.17us 857.64K
2028 // pthrd_rwlock_ping_pong(burn100k) 57.43% 1.18us 845.86K
2029 // ----------------------------------------------------------------------------
2030 // folly_rwspin_ping_pong(burn300k) 2.03us 492.99K
2031 // shmtx_w_bare_ping_pong(burn300k) 99.98% 2.03us 492.88K
2032 // shmtx_r_bare_ping_pong(burn300k) 99.94% 2.03us 492.68K
2033 // folly_ticket_ping_pong(burn300k) 99.88% 2.03us 492.40K
2034 // boost_shared_ping_pong(burn300k) 81.43% 2.49us 401.47K
2035 // pthrd_rwlock_ping_pong(burn300k) 83.22% 2.44us 410.29K
2036 // ----------------------------------------------------------------------------
2037 // folly_rwspin_ping_pong(burn1M) 677.07ns 1.48M
2038 // shmtx_w_bare_ping_pong(burn1M) 100.50% 673.74ns 1.48M
2039 // shmtx_r_bare_ping_pong(burn1M) 100.14% 676.12ns 1.48M
2040 // folly_ticket_ping_pong(burn1M) 100.44% 674.14ns 1.48M
2041 // boost_shared_ping_pong(burn1M) 93.04% 727.72ns 1.37M
2042 // pthrd_rwlock_ping_pong(burn1M) 94.52% 716.30ns 1.40M
2043 // ============================================================================
2045 int main(int argc, char** argv) {
2046 (void)folly_rwspin_reads;
2047 (void)shmtx_wr_pri_reads;
2048 (void)shmtx_w_bare_reads;
2049 (void)shmtx_rd_pri_reads;
2050 (void)shmtx_r_bare_reads;
2051 (void)folly_ticket_reads;
2052 (void)boost_shared_reads;
2053 (void)pthrd_rwlock_reads;
2063 (void)folly_rwspin_ping_pong;
2064 (void)shmtx_w_bare_ping_pong;
2065 (void)shmtx_r_bare_ping_pong;
2066 (void)folly_ticket_ping_pong;
2067 (void)boost_shared_ping_pong;
2068 (void)pthrd_rwlock_ping_pong;
2070 testing::InitGoogleTest(&argc, argv);
2071 gflags::ParseCommandLineFlags(&argc, &argv, true);
2072 int rv = RUN_ALL_TESTS();
2073 folly::runBenchmarksOnFlag();