Skip to content

Commit

Permalink
a bug fixed to avoid segment falut
Browse files Browse the repository at this point in the history
  • Loading branch information
F-Feng committed May 11, 2024
1 parent 4021c1c commit f4baa4d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
Binary file not shown.
23 changes: 7 additions & 16 deletions src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,7 @@ void add_mode2_p(const pc_pair_ptr_lst &terms1, const pc_pair_ptr_lst &terms2, p
auto call_back = [&]() {
while(true) {
long i = atomic_index.fetch_add(1);
if(i>=todo_vec.size()) {
flint_cleanup();
return;
}
if(i>=todo_vec.size()) return;
auto mode = todo_vec[i].first;
auto items = todo_vec[i].second;
if(mode==1) {
Expand Down Expand Up @@ -1808,7 +1805,6 @@ void forward_stage(sector_count_t ssector_number) {
}
} else { // original version
COEFF o;
//if(common::run_sector && !common::silent) cout << to_substitute.size() << flush;
for (auto itrTo = to_substitute.begin(); itrTo != to_substitute.end(); ++itrTo) {
bool changed = false;
auto startTerm = itrTo->begin();
Expand All @@ -1818,10 +1814,10 @@ void forward_stage(sector_count_t ssector_number) {
for (; itrTerm != itrTo->end(); ++itrTerm) {
if (p == (*itrTerm)->first) {
_div_neg_(o, (*itrTerm)->second, (*(itrFrom->back())).second);
++itrTerm; // we move it before, or it will be invalidated
if(common::tp<2) mul_add_to(*itrTo, *itrFrom, o, false);
else mul_add_to_p(*itrTo, *itrFrom, o, false);
changed = true;
++itrTerm; // we move it before, or it will be invalidated
break;
} else if (p < (*itrTerm) -> first) {
break; // this relation does not go there
Expand Down Expand Up @@ -2416,7 +2412,7 @@ void mul_add_to_p(pc_pair_ptr_lst &terms1, const pc_pair_ptr_lst &terms2, const
++itr1;
} else if ((itr1 == terms1.end()) || ((*itr2)->first < (*itr1)->first)) { // second equation only. have to multiply
if(!is_zero((*itr2)->second)) {
itr1 = terms1.emplace(itr1, make_pc_ptr((*itr2)->first, CO_0)); // to set point from *itr2
itr1 = terms1.emplace(itr1, *itr2); // to set point from *itr2
itr_vec.push_back(itr1);
vector<pc_pair_ptr> items { *itr2 };
size_t l = (*itr2)->second.length();
Expand All @@ -2442,10 +2438,7 @@ void mul_add_to_p(pc_pair_ptr_lst &terms1, const pc_pair_ptr_lst &terms2, const
auto call_back = [&]() {
while(true) {
long i = atomic_index.fetch_add(1);
if(i>=todo_vec.size()) {
flint_cleanup();
return;
}
if(i>=todo_vec.size()) return;
auto mode = todo_vec[i].first;
auto items = todo_vec[i].second;
if(mode==1) {
Expand Down Expand Up @@ -2473,18 +2466,16 @@ void mul_add_to_p(pc_pair_ptr_lst &terms1, const pc_pair_ptr_lst &terms2, const
for(int i=0; i<todo_vec.size(); i++) {
auto mode = todo_vec[i].first;
auto items = todo_vec[i].second;
if(mode==1) {
rterms_vec[i] = items[0];
} else if(mode==2) {
if(mode==2) {
COEFF o;
_mul_(o, items[0]->second, coeff);
rterms_vec[i] = make_pc_ptr(items[0]->first, std::move(o));
} else {
} else if(mode==3) {
COEFF o;
_mul_(o, items[1]->second, coeff);
_add_(o, o, items[0]->second);
rterms_vec[i] = make_pc_ptr(items[0]->first, std::move(o));
}
} else throw std::runtime_error("strange mode found.");
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/taskspool.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ inline void TasksPool::init(size_t nt) {
{
std::unique_lock<std::mutex> lock(this->queue_mutex);
this->condition.wait(lock, [this]{ return this->done || !this->tasks.empty(); });
if(this->done && this->tasks.empty()) return;
if(this->done && this->tasks.empty()) {
flint_cleanup();
return;
}
task = std::move(this->tasks.front());
this->tasks.pop();
}
Expand Down

0 comments on commit f4baa4d

Please sign in to comment.