Only lock once per iteration
This commit is contained in:
parent
d218af9c4a
commit
ff65b49da4
17
src/main.cpp
17
src/main.cpp
|
@ -183,15 +183,9 @@ int main(int argc, char *argv[]) {
|
||||||
for (unsigned int w = 1; w <= wc; w++) {
|
for (unsigned int w = 1; w <= wc; w++) {
|
||||||
workers.push_back(std::thread([&it, &n_done, &it_lock, &all_fires,
|
workers.push_back(std::thread([&it, &n_done, &it_lock, &all_fires,
|
||||||
&residentials, &out_dir, w, distance]() {
|
&residentials, &out_dir, w, distance]() {
|
||||||
for (;;) {
|
|
||||||
it_lock.lock();
|
it_lock.lock();
|
||||||
if (it == all_fires.end()) {
|
|
||||||
std::cout << "Worker " << w << " done! (finished " << n_done
|
|
||||||
<< "/" << all_fires.size() << ")" << std::endl;
|
|
||||||
it_lock.unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
while (it != all_fires.end()) {
|
||||||
const auto& month_data = *(it++);
|
const auto& month_data = *(it++);
|
||||||
auto& month = month_data.name;
|
auto& month = month_data.name;
|
||||||
auto& month_fires = month_data.days;
|
auto& month_fires = month_data.days;
|
||||||
|
@ -225,12 +219,13 @@ int main(int argc, char *argv[]) {
|
||||||
outf << '\n';
|
outf << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
it_lock.lock();
|
||||||
std::lock_guard<std::mutex> lk(it_lock);
|
|
||||||
|
|
||||||
n_done++;
|
n_done++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
std::cout << "Worker " << w << " done! (finished " << n_done
|
||||||
|
<< "/" << all_fires.size() << ")" << std::endl;
|
||||||
|
it_lock.unlock();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue