edits
authorweiyu <weiyuluo1232@gmail.com>
Tue, 25 Aug 2020 22:14:15 +0000 (15:14 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Tue, 25 Aug 2020 22:14:15 +0000 (15:14 -0700)
libthreads.cc
model.cc
pthread.cc

index 5ff106c8535982bd82835366a0444ce77c0f300e..c06a9be23d9a15d75d531c858eedc9e5362919c3 100644 (file)
@@ -28,7 +28,7 @@ int thrd_join(thrd_t t)
 /** A no-op, for now */
 void thrd_yield(void)
 {
-       model->switch_to_master(new ModelAction(THREAD_YIELD, std::memory_order_seq_cst, thread_current(), VALUE_NONE));
+       model->switch_thread(new ModelAction(THREAD_YIELD, std::memory_order_seq_cst, thread_current(), VALUE_NONE));
 }
 
 thrd_t thrd_current(void)
index 090743a49ff0ce6da1a1627acdd1367ebdc5c0ac..d9671a30b7b31bac2b182135edf8c7f26bd1e247 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -346,7 +346,6 @@ uint64_t ModelChecker::switch_to_master(ModelAction *act)
 
 void ModelChecker::startRunExecution(Thread *old) 
 {
-
        if (params.traceminsize != 0 &&
                        execution->get_curr_seq_num() > checkfree) {
                checkfree += params.checkthreshold;
@@ -390,12 +389,12 @@ Thread* ModelChecker::getNextThread()
                if (act && execution->is_enabled(thr) && !execution->check_action_enabled(act)) {
                        scheduler->sleep(thr);
                }
-
-       chooseThread(act, thr);
+               chooseThread(act, thr);
        }
        return nextThread;
 }
 
+/* Swap back to system_context and terminate this execution */
 void ModelChecker::finishRunExecution(Thread *old) 
 {
        scheduler->set_current_thread(NULL);
@@ -515,9 +514,9 @@ void ModelChecker::handleChosenThread(Thread *old)
                chosen_thread->set_pending(NULL);
                chosen_thread = NULL;
                // Allow this thread to stash the next pending action
-               if (should_terminate_execution())
-                       finishRunExecution(th);
-               else
+//             if (should_terminate_execution())
+//                     finishRunExecution(th);
+//             else
                        startRunExecution(th);
        } else {
                /* Consume the next action for a Thread */
@@ -566,8 +565,6 @@ void ModelChecker::run()
                        if (break_execution)
                                break;
 
-                       thread_chosen = false;
-                       curr_thread_num = 1;
                        startRunExecution(NULL);
                } while (!should_terminate_execution());
 
index b5fb7ce964200750a108412c63041de7cea56c3d..e453f1b27e45b2188c73231fbac3d436cd15ac6a 100644 (file)
@@ -24,10 +24,8 @@ int pthread_create(pthread_t *t, const pthread_attr_t * attr,
 
        struct pthread_params params = { start_routine, arg };
 
-       ModelAction *act = new ModelAction(PTHREAD_CREATE, std::memory_order_seq_cst, t, (uint64_t)&params);
-
        /* seq_cst is just a 'don't care' parameter */
-       model->switch_to_master(act);
+       model->switch_to_master(new ModelAction(PTHREAD_CREATE, std::memory_order_seq_cst, t, (uint64_t)&params));
 
        return 0;
 }
@@ -54,7 +52,7 @@ int pthread_detach(pthread_t t) {
 
 /* Take care of both pthread_yield and c++ thread yield */
 int sched_yield() {
-       model->switch_to_master(new ModelAction(THREAD_YIELD, std::memory_order_seq_cst, thread_current(), VALUE_NONE));
+       model->switch_thread(new ModelAction(THREAD_YIELD, std::memory_order_seq_cst, thread_current(), VALUE_NONE));
        return 0;
 }
 
@@ -205,7 +203,7 @@ int pthread_cond_timedwait(pthread_cond_t *p_cond,
        cdsc::snapcondition_variable *v = execution->getCondMap()->get(p_cond);
        cdsc::snapmutex *m = execution->getMutexMap()->get(p_mutex);
 
-       model->switch_to_master(new ModelAction(ATOMIC_TIMEDWAIT, std::memory_order_seq_cst, v, (uint64_t) m));
+       model->switch_thread(new ModelAction(ATOMIC_TIMEDWAIT, std::memory_order_seq_cst, v, (uint64_t) m));
        m->lock();
 
        // model_print("Timed_wait is called\n");