MCPcopy Create free account
hub / github.com/David-Haim/concurrencpp / async_insert

Function async_insert

test/source/thread_sanitizer/async_lock.cpp:91–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91void async_insert(runtime& runtime) {
92 async_lock mtx;
93 std::vector<size_t> vector;
94
95 const size_t worker_count = concurrencpp::details::thread::hardware_concurrency();
96 constexpr size_t cycles = 500'000;
97
98 std::vector<std::shared_ptr<worker_thread_executor>> workers(worker_count);
99 for (auto& worker : workers) {
100 worker = runtime.make_worker_thread_executor();
101 }
102
103 std::vector<result<void>> results(worker_count);
104
105 const auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(4);
106
107 for (size_t i = 0; i < worker_count; i++) {
108 results[i] = insert({}, workers[i], mtx, vector, i * cycles, (i + 1) * cycles, deadline);
109 }
110
111 for (size_t i = 0; i < worker_count; i++) {
112 results[i].get();
113 }
114
115 {
116 auto lock = mtx.lock(workers[0]).run().get();
117 if (vector.size() != cycles * worker_count) {
118 std::cerr << "async_lock test failed, vector.size() != cycles * worker_count, " << vector.size()
119 << " != " << cycles * worker_count << std::endl;
120 }
121
122 std::sort(vector.begin(), vector.end());
123
124 for (size_t i = 0; i < worker_count * cycles; i++) {
125 if (vector[i] != i) {
126 std::cerr << "async_lock test failed, vector[i] != i, " << vector[i] << " != " << i << std::endl;
127 }
128 }
129 }
130}

Callers 1

mainFunction · 0.85

Calls 8

runMethod · 0.80
lockMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
insertFunction · 0.70
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected