source: doc/theses/colby_parsons_MMAth/benchmarks/mutex_stmt/cpp/baseline.cc @ f9ad69d

Last change on this file since f9ad69d was 0da7181, checked in by caparsons <caparson@…>, 20 months 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
8cpp_test_spinlock LOCKS;
9
10bool done = false;
11uint64_t total = 0;
12void thread_main() {
13    BENCH( lock( LOCKS ); unlock( LOCKS );, total, done )
14}
15
16int 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.