if (ret)
return ret;
- /* start_routine == NULL means this is our initial context */
- if (!start_routine)
- return 0;
-
/* Initialize new managed context */
stack = stack_allocate(STACK_SIZE);
context.uc_stack.ss_sp = stack;
state = THREAD_CREATED;
id = model->get_next_id();
*user_thread = id;
-}
-
-Thread::Thread(thrd_t *t) {
- /* system thread */
- user_thread = t;
- start_routine = NULL;
- arg = NULL;
-
- create_context();
- stack = NULL;
- state = THREAD_CREATED;
- id = model->get_next_id();
- *user_thread = id;
- model->set_system_context(&context);
+ parent = thread_current();
}
Thread::~Thread()
/* Stopped while running; i.e., completed */
curr->complete();
else
- DEBUG("ERROR: current thread in unexpected state??\n");
+ ASSERT(false);
}
next = model->scheduler->next_thread();
if (next)
do {
/* Start user program */
- thrd_create(&user_thread, &user_main, NULL);
+ model->add_thread(new Thread(&user_thread, &user_main, NULL));
/* Wait for all threads to complete */
thread_wait_finish();