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 d3fcbb4..0cb6709 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 70ea4cd..136898e 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 fc5c84a..8af66bd 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();