• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Nonogram solver


Commit MetaInfo

Revision7caf5c8ad43e7ff8a2d108b9b66698d332be2702 (tree)
Time2021-03-06 14:38:45
AuthorAlexander Larin <scalar438@gmai...>
CommiterAlexander Larin

Log Message

Add items counter

Change Summary

Incremental Difference

diff -r 1407e7ac3c9c -r 7caf5c8ad43e main.cpp
--- a/main.cpp Sat Mar 06 08:27:52 2021 +0300
+++ b/main.cpp Sat Mar 06 08:38:45 2021 +0300
@@ -1,10 +1,12 @@
11 #include "row_solver_bf.hpp"
22 #include <cell.hpp>
3+#include <row_solver.hpp>
4+
5+#include <chrono>
36 #include <iostream>
47 #include <memory>
58 #include <mutex>
69 #include <optional>
7-#include <row_solver.hpp>
810 #include <string_view>
911 #include <thread>
1012 #include <vector>
@@ -112,15 +114,14 @@
112114 return res;
113115 }
114116
115-void run_in_one_thread(std::shared_ptr<std::mutex> mtx,
116- vector<pair<vector<Block> *, string *>> &data,
117+void run_in_one_thread(std::mutex &mtx, vector<pair<vector<Block> *, string *>> &data,
117118 optional<tuple<string, string, string>> &answer_mismatch)
118119 {
119120 while (1)
120121 {
121122 pair<vector<Block> *, string *> one_run_data;
122123 {
123- std::lock_guard g(*mtx);
124+ std::lock_guard g(mtx);
124125 if (data.empty()) break;
125126 one_run_data = data.back();
126127 data.pop_back();
@@ -128,16 +129,28 @@
128129 auto res = solve(*one_run_data.second, *one_run_data.first);
129130 if (res.first != res.second)
130131 {
131- std::lock_guard g(*mtx);
132+ std::lock_guard g(mtx);
132133 data.clear();
133134 answer_mismatch = make_tuple(*one_run_data.second, res.first, res.second);
134135 }
135136 }
136137 }
137138
139+void items_counter(std::mutex &mtx, vector<pair<vector<Block> *, string *>> &input_data)
140+{
141+ while (1)
142+ {
143+ this_thread::sleep_for(std::chrono::seconds(1));
144+ lock_guard g(mtx);
145+ auto s = input_data.size();
146+ if (s == 0) break;
147+ cout << "Items remaining: " << s << '\n';
148+ }
149+}
150+
138151 int main()
139152 {
140- const int n = 3;
153+ const int n = 7;
141154 auto all_blocks = gen_all_blocks(n);
142155 auto all_rows = gen_all_rows(n);
143156 vector<pair<vector<Block> *, string *>> all_input;
@@ -149,12 +162,12 @@
149162 }
150163 }
151164 vector<thread> v_thrd;
152- auto mtx = std::make_shared<std::mutex>();
165+ std::mutex mtx;
153166 optional<tuple<string, string, string>> answer_mismatch;
154167 for (unsigned int i = 0; i != std::thread::hardware_concurrency(); ++i)
155- v_thrd.emplace_back(
156- thread(run_in_one_thread, mtx, std::ref(all_input), std::ref(answer_mismatch)));
157-
168+ v_thrd.emplace_back(thread(run_in_one_thread, std::ref(mtx), std::ref(all_input),
169+ std::ref(answer_mismatch)));
170+ v_thrd.push_back(thread(items_counter, ref(mtx), ref(all_input)));
158171 for (auto &thrd : v_thrd)
159172 thrd.join();
160173 if (answer_mismatch)