Replace some switch_to_master with switch_thread
authorweiyu <weiyuluo1232@gmail.com>
Tue, 11 Aug 2020 19:30:52 +0000 (12:30 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Tue, 11 Aug 2020 19:30:52 +0000 (12:30 -0700)
cmodelint.cc
model.cc
threads.cc

index d3fcbb4656919157220ed5a4197ee3c58b723e75..0cb67091f36eda07cace08dc4cdee1362b61711e 100644 (file)
@@ -80,12 +80,12 @@ uint64_t model_rmwrcas_action_helper(void *obj, int atomic_index, uint64_t oldva
 
 uint64_t model_rmwr_action_helper(void *obj, int atomic_index, const char *position) {
        ensureModel();
-       return model->switch_to_master(new ModelAction(ATOMIC_RMWR, position, orders[atomic_index], obj));
+       return model->switch_thread(new ModelAction(ATOMIC_RMWR, position, orders[atomic_index], obj));
 }
 
 void model_rmw_action_helper(void *obj, uint64_t val, int atomic_index, const char * position) {
        ensureModel();
-       model->switch_to_master(new ModelAction(ATOMIC_RMW, position, orders[atomic_index], obj, val));
+       model->switch_thread(new ModelAction(ATOMIC_RMW, position, orders[atomic_index], obj, val));
 }
 
 void model_rmwc_action_helper(void *obj, int atomic_index, const char *position) {
@@ -161,7 +161,7 @@ CDSATOMICLOAD(64)
 #define CDSATOMICSTORE(size)                                            \
        void cds_atomic_store ## size(void * obj, uint ## size ## _t val, int atomic_index, const char * position) { \
                ensureModel();                                                        \
-               model->switch_to_master(new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)); \
+               model->switch_thread(new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)); \
                *((volatile uint ## size ## _t *)obj) = val;                     \
                thread_id_t tid = thread_current()->get_id();           \
                for(int i=0;i < size / 8;i++) {                       \
index 70ea4cd6534a9910ac176c1f497882e1ae6d3395..136898e913808803972f63d5b7bcd67b1b945a5e 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -488,8 +488,10 @@ uint64_t ModelChecker::switch_thread(ModelAction *act)
        Thread* next = getNextThread();
        if (next != nullptr) 
                handleNewValidThread(old, next);
-       else
+       else {
+               old->set_state(THREAD_READY);   // Just to avoid the first ASSERT in ModelExecution::take_step 
                handleChosenThread(old);
+       }
 
        return old->get_return_value();
 }
@@ -593,8 +595,8 @@ void ModelChecker::run()
        initstate(423121, random_state, sizeof(random_state));
        checkfree = params.checkthreshold;
        for(int exec = 0;exec < params.maxexecutions;exec++) {
+               chosen_thread = init_thread;
                do {
-                       chosen_thread = init_thread;
                        thread_chosen = false;
                        curr_thread_num = 1;
                        startRunExecution(&system_context);
index fc5c84a160296f12f7b3c39db3a84c898bafee9f..8af66bde53a6946a153d2009c04e554495d4b8eb 100644 (file)
@@ -242,7 +242,7 @@ void setup_context() {
        Thread * curr_thread = thread_current();
 
        /* Add dummy "start" action, just to create a first clock vector */
-       model->switch_to_master(new ModelAction(THREAD_START, std::memory_order_seq_cst, curr_thread));
+       model->switch_thread(new ModelAction(THREAD_START, std::memory_order_seq_cst, curr_thread));
 
        real_init_all();