relacy
relacy copied to clipboard
Why assertion passed but must fail
struct data_race_test : rl::test_suite<data_race_test, 2>{
rl::atomic<int> ff;
rl::atomic<int> nexec;
void before(){
nexec($) = 0;
ff($) = 0;
}
void thread(unsigned id){
if(id == 0){
// Thread 0
if(ff($)==0){ // 1. 7.
ff($)++; // 2 ff=1. 8 ff=1.
nexec($)++; // 3 exec=1. 9 exec=2.
assertions1(); // 6. 10 **must fail but doesnt!**
}else{
ff($)++;
}
}else if(id == 1){
// Thread 1
if(nexec($)>0){ // 4.
ff($)--; // 5 ff=0.
if(ff($)==0){
nexec($)--;
assertions1();
}
}
}
}
void assertions1(){
int ex = nexec($);
RL_ASSERT(ex >= 0 && ex<=1);
}
};
int main(){
rl::test_params p;
p.search_type = rl::sched_full;
//p.iteration_count = 1000000;
rl::simulate<data_race_test>(p);
}
data_race_test iterations: 41 total time: 1 throughput: 41000