|
Last change
on this file since 8a9a3ab was 0da7181, checked in by caparsons <caparson@…>, 3 years ago |
|
added randomized lock ordering bench for mutexstmt
|
-
Property mode
set to
100644
|
|
File size:
711 bytes
|
| Line | |
|---|
| 1 | #include <cstdio>
|
|---|
| 2 | #include <mutex>
|
|---|
| 3 | #include <thread>
|
|---|
| 4 | #include <chrono>
|
|---|
| 5 | #include "../bench.h"
|
|---|
| 6 | #include "cppLock.hpp"
|
|---|
| 7 |
|
|---|
| 8 | cpp_test_spinlock LOCKS;
|
|---|
| 9 |
|
|---|
| 10 | bool done = false;
|
|---|
| 11 | uint64_t total = 0;
|
|---|
| 12 | void thread_main() {
|
|---|
| 13 | BENCH( lock( LOCKS ); unlock( LOCKS );, total, done )
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | int main( int argc, char * argv[] ) {
|
|---|
| 17 | BENCH_START()
|
|---|
| 18 | std::thread myThreads[threads];
|
|---|
| 19 |
|
|---|
| 20 | for (int i = 0; i < threads; i++) {
|
|---|
| 21 | myThreads[i] = std::thread(thread_main); // move constructed
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | std::this_thread::sleep_for (std::chrono::seconds(10));
|
|---|
| 25 | done = true;
|
|---|
| 26 |
|
|---|
| 27 | for (int i = 0; i < threads; i++) {
|
|---|
| 28 | myThreads[i].join();
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | printf( "%lu\n", total );
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | // Local Variables: //
|
|---|
| 35 | // tab-width: 4 //
|
|---|
| 36 | // End: //
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.