Last change
on this file since c4aca65 was
6e6989c,
checked in by caparsons <caparson@…>, 18 months ago
|
added mutex stmt benchmarking
|
-
Property mode set to
100644
|
File size:
711 bytes
|
Rev | Line | |
---|
[6e6989c] | 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( std::scoped_lock lock( 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.