- DEBUG("completed thread %d\n", thread_current()->get_id());
- state = THREAD_COMPLETED;
- stack_free(stack);
+ if (state != THREAD_COMPLETED) {
+ DEBUG("completed thread %d\n", get_id());
+ state = THREAD_COMPLETED;
+ if (stack)
+ stack_free(stack);
+ }
model->scheduler->add_thread(curr);
else if (curr->get_state() == THREAD_RUNNING)
/* Stopped while running; i.e., completed */
model->scheduler->add_thread(curr);
else if (curr->get_state() == THREAD_RUNNING)
/* Stopped while running; i.e., completed */
- /* Start user program */
- thrd_create(&user_thread, &user_main, NULL);
+ do {
+ /* Start user program */
+ thrd_create(&user_thread, &user_main, NULL);