Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why assertion passed but must fail #3

Open
bragcustom opened this issue Sep 6, 2016 · 0 comments
Open

Why assertion passed but must fail #3

bragcustom opened this issue Sep 6, 2016 · 0 comments

Comments

@bragcustom
Copy link

bragcustom commented Sep 6, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant