Simple example that Relacy cannot fails to find error(assert)

58 views
Skip to first unread message

klba...@gmail.com

unread,
Sep 6, 2016, 3:43:08 AM9/6/16
to Relacy Race Detector
Hi. Why assertion passed but it must fail?
I wrote execution order in comments in which the assertion 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 nexec=1.   9 nexec=2.
                assertions1
();  // 4.           10 must fail but dont!
           
}else{
                ff
($)++;
           
}
       
}else if(id == 1){
           
// Thread 1
           
if(nexec($)>0){     // 5.
                ff
($)--;        // 6 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);
}



Dmitry Vyukov

unread,
Sep 6, 2016, 5:17:36 AM9/6/16
to rel...@googlegroups.com
Hello,

You create only 2 threads, but seem to assume that 3 threads are running.

You need to create 3 threads:

struct data_race_test : rl::test_suite<data_race_test, 3>{

And then execute first part of code by 2 threads:

if(id == 0 || id == 2){

Note the test executed multiple times, but each run starts from clean
slate. No state is accumulated between runs.


--
Dmitry Vyukov

All about lockfree/waitfree algorithms, multicore, scalability,
parallel computing and related topics:
http://www.1024cores.net
Reply all
Reply to author
Forward
0 new messages