| 46 | } |
| 47 | |
| 48 | void runThreads(int num) |
| 49 | { |
| 50 | SpinLock exclusiveLock; |
| 51 | //Create 50 threads |
| 52 | exclusiveLock.lock(); //lock it so that all threads block |
| 53 | std::vector<std::shared_ptr<std::thread>> threads; |
| 54 | auto start = std::chrono::high_resolution_clock::now(); |
| 55 | for (int i = 0; i < 20; ++i) { |
| 56 | threads.push_back(std::make_shared<std::thread>(runnable, &exclusiveLock)); |
| 57 | } |
| 58 | exclusiveLock.unlock(); //unlock to start contention |
| 59 | for (auto& t : threads) { |
| 60 | t->join(); |
| 61 | } |
| 62 | auto end = std::chrono::high_resolution_clock::now(); |
| 63 | std::cout << "Total spin time " << num << ": " |
| 64 | << std::chrono::duration_cast<ms>(end-start).count() |
| 65 | << "ms" << std::endl; |
| 66 | } |
| 67 | |
| 68 | void spinlockSettings( |
| 69 | size_t min, |
no test coverage detected