//Thread 0 isn't a real thread, so skip it..
for(unsigned int i = 1;i < thread_map.size();i++) {
Thread * t = thread_map[i];
- if (t->get_state() == THREAD_COMPLETED)
+ if (t->is_complete())
continue;
thread_id_t tid = int_to_id(i);
ClockVector * cv = get_cv(tid);
thread_chosen = false;
curr_thread_num = 1;
- Thread *thr = getNextThread();
+ Thread *thr = getNextThread(old);
if (thr != nullptr) {
scheduler->set_current_thread(thr);
}
}
-Thread* ModelChecker::getNextThread()
+Thread* ModelChecker::getNextThread(Thread *old)
{
Thread *nextThread = nullptr;
for (unsigned int i = curr_thread_num;i < get_num_threads();i++) {
thread_id_t tid = int_to_id(i);
Thread *thr = get_thread(tid);
- if (!thr->is_complete() && !thr->get_pending()) {
- curr_thread_num = i;
- nextThread = thr;
- break;
+ if (!thr->is_complete()) {
+ if (!thr->get_pending()) {
+ curr_thread_num = i;
+ nextThread = thr;
+ break;
+ }
+ } else if (thr != old && !thr->is_freed()) {
+ thr->freeResources();
}
/* Don't schedule threads which should be disabled */
chooseThread(act, old);
curr_thread_num++;
- Thread* next = getNextThread();
+ Thread* next = getNextThread(old);
if (next != nullptr) {
scheduler->set_current_thread(next);
if (Thread::swap(old, next) < 0) {
void finishRunExecution(Thread *old);
void consumeAction();
void chooseThread(ModelAction *act, Thread *thr);
- Thread * getNextThread();
+ Thread * getNextThread(Thread *old);
void handleChosenThread(Thread *old);
modelclock_t checkfree;
*/
THREAD_BLOCKED,
/** Thread has completed its execution */
- THREAD_COMPLETED
+ THREAD_COMPLETED,
+ THREAD_FREED
} thread_state;
void * get_pthread_return() { return pthread_return; }
/** @return True if this thread is finished executing */
- bool is_complete() const { return state == THREAD_COMPLETED; }
+ bool is_complete() const { return state == THREAD_COMPLETED || state == THREAD_FREED; }
+
+ /** @return True if this thread has finished and its resources have been freed */
+ bool is_freed() const { return state == THREAD_FREED; }
/** @return True if this thread is blocked */
bool is_blocked() const { return state == THREAD_BLOCKED; }
stack_free(stack);
#ifdef TLS
if (this != model->getInitThread()) {
- ASSERT(thread_current()==NULL);
real_pthread_mutex_unlock(&mutex2);
real_pthread_join(thread, NULL);
stack_free(helper_stack);
}
#endif
+ state = THREAD_FREED;
}
/**
acq_fence_cv(new ClockVector()),
creation(NULL),
pending(NULL),
+ wakeup_state(false),
start_routine(NULL),
arg(NULL),
stack(NULL),
acq_fence_cv(new ClockVector()),
creation(NULL),
pending(NULL),
+ wakeup_state(false),
start_routine(func),
pstart_routine(NULL),
arg(a),
acq_fence_cv(new ClockVector()),
creation(NULL),
pending(NULL),
+ wakeup_state(false),
start_routine(NULL),
pstart_routine(func),
arg(a),