MCPcopy Create free account
hub / github.com/bloomberg/quantum / runThreads

Function runThreads

tests/quantum_locks_tests.cpp:48–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48void 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
68void spinlockSettings(
69 size_t min,

Callers 1

spinlockSettingsFunction · 0.85

Calls 3

joinMethod · 0.80
lockMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected