Skip to content

Commit a938d19

Browse files
committed
🐛 bug fixed in predCP
1 parent 480cd2d commit a938d19

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

async/asyncTermSet.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ namespace wamcer {
4242

4343
void AsyncTermSet::pop(smt::Term& term) {
4444
auto lck = std::unique_lock(mux);
45-
// pop one term in data and assign it to term
46-
if (size() > 0) {
45+
if (!data.empty()) {
4746
term = *data.begin();
4847
data.erase(term);
4948
}

core/runner.cpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ namespace wamcer {
229229
}
230230
}
231231

232+
// There are bugs in the solver's data for concurrent access.
232233
bool
233234
Runner::runPredCP(std::string path,
234235
const std::function<void(std::string &, TransitionSystem &, Term &)> &decoder,
@@ -244,7 +245,8 @@ namespace wamcer {
244245
// pred generation
245246
auto preds = AsyncTermSet();
246247
auto predsGen = new DirectConstructor(ts, p, preds, s);
247-
predsGen->generatePreds(0, 1);
248+
predsGen->generatePreds();
249+
logger.log(defines::logPredCP, 1, "Predicates size: {}.", preds.size());
248250

249251
predCP.insert(preds, 0);
250252
auto threads = std::vector<std::thread>();
@@ -253,15 +255,19 @@ namespace wamcer {
253255
predCP.propBMC();
254256
});
255257
threads.push_back(std::move(t1));
256-
for (int i = 0; i < bound; ++i) {
257-
auto check = std::thread([&] {
258+
259+
// pred in pools[k] means that safe in k steps
260+
// check 0 - bound-1 pools
261+
for (int i = 0; i < bound; i++) {
262+
threads.emplace_back([&](int i) {
258263
predCP.check(i);
259-
});
260-
threads.push_back(std::move(check));
261-
auto prove = std::thread([&] {
264+
}, i);
265+
}
266+
// prove 1 - bound pools
267+
for (int i = 1; i <= bound; ++i) {
268+
threads.emplace_back([&](int i) {
262269
predCP.prove(i);
263-
});
264-
threads.push_back(std::move(prove));
270+
}, i);
265271
}
266272

267273
for (auto &t: threads) {

engines/PredCP.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ namespace wamcer {
2222
if (at >= max_step) {
2323
return false;
2424
}
25+
auto lock = std::unique_lock<std::mutex>(global_mux);
2526
auto new_ts = TransitionSystem::copy(ts);
2627
auto bmc = BMCChecker(new_ts);
28+
lock.unlock();
2729
while (true) {
30+
logger.log(defines::logPredCP, 1, "PredCP: check at {}, with pred size: {}", at, preds.size(at));
2831
while (preds.size(at) == 0) {
2932
auto lck = std::unique_lock(mutexes[at]);
3033
cvs[at].wait(lck);
@@ -45,15 +48,17 @@ namespace wamcer {
4548
}
4649

4750
bool PredCP::prove(int at) {
48-
if (at >= max_step) {
51+
if (at > max_step) {
4952
return false;
5053
}
5154
while (at > cur_step) {
5255
auto lck = std::unique_lock(prove_wait_mux);
5356
prove_wait_cv.wait(lck);
5457
}
58+
auto lock = std::unique_lock<std::mutex>(global_mux);
5559
auto new_ts = TransitionSystem::copy(ts);
5660
auto prover = InductionProver(new_ts, prop);
61+
lock.unlock();
5762
while (true) {
5863
{
5964
auto lck = std::unique_lock(mutexes[at]);
@@ -78,8 +83,10 @@ namespace wamcer {
7883
}
7984

8085
void PredCP::propBMC() {
86+
auto lock = std::unique_lock<std::mutex>(global_mux);
8187
auto new_ts = TransitionSystem::copy(ts);
8288
auto bmc = BMCChecker(new_ts);
89+
lock.unlock();
8390
while (true) {
8491
if (bmc.check(cur_step + 1, prop)) {
8592
logger.log(defines::logPredCP, 1, "propBMC: prop is checked safe at {} step", cur_step + 1);
@@ -93,12 +100,12 @@ namespace wamcer {
93100
}
94101
}
95102

96-
void PredCP::insert(const smt::TermVec& terms, int at) {
103+
void PredCP::insert(const smt::TermVec &terms, int at) {
97104
preds.insert(terms, at);
98105
cvs[at].notify_all();
99106
}
100107

101-
void PredCP::insert(AsyncTermSet& terms, int at) {
108+
void PredCP::insert(AsyncTermSet &terms, int at) {
102109
terms.map([&](const smt::Term &t) {
103110
preds.insert({t}, at);
104111
});

engines/PredCP.h

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef WAMCER_PREDCP_H
66
#define WAMCER_PREDCP_H
77

8+
#include <atomic>
89
#include "async/asyncPreds.h"
910
#include "core/unroller.h"
1011
#include "utils/logger.h"
@@ -27,6 +28,7 @@ namespace wamcer {
2728
void insert(AsyncTermSet &terms, int at);
2829

2930
private:
31+
std::mutex global_mux;
3032
std::vector<std::mutex> mutexes;
3133
std::vector<std::condition_variable> cvs;
3234
std::mutex prove_wait_mux;

0 commit comments

Comments
 (0)