X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=threads.cc;h=792014e62b4d3c88c1ecc052a4de120c25cace52;hb=84e24d516d4e9dbd30f1fff7e9a185d1540d20eb;hp=80957adf7b1709c015b4a30bc82deacc98767b92;hpb=10de861d3a9908e75b6f94283cc67b3f1b4d93ab;p=model-checker.git diff --git a/threads.cc b/threads.cc index 80957ad..792014e 100644 --- a/threads.cc +++ b/threads.cc @@ -9,23 +9,35 @@ static void * stack_allocate(size_t size) { - return userMalloc(size); + return malloc(size); } static void stack_free(void *stack) { - userFree(stack); + free(stack); } Thread * thread_current(void) { + ASSERT(model); return model->scheduler->get_current_thread(); } -/* This method just gets around makecontext not being 64-bit clean */ - +/** + * Provides a startup wrapper for each thread, allowing some initial + * model-checking data to be recorded. This method also gets around makecontext + * not being 64-bit clean + */ void thread_startup() { - Thread * curr_thread=thread_current(); + Thread * curr_thread = thread_current(); + + /* TODO -- we should make this event always immediately follow the + CREATE event, so we don't get redundant traces... */ + + /* 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)); + + /* Call the actual thread function */ curr_thread->start_routine(curr_thread->arg); } @@ -68,19 +80,20 @@ void Thread::complete() } } -Thread::Thread(thrd_t *t, void (*func)(void *), void *a) { +Thread::Thread(thrd_t *t, void (*func)(void *), void *a) : + start_routine(func), + arg(a), + user_thread(t), + state(THREAD_CREATED), + last_action_val(VALUE_NONE) +{ int ret; - user_thread = t; - start_routine = func; - arg = a; - /* Initialize state */ ret = create_context(); if (ret) printf("Error in create_context\n"); - state = THREAD_CREATED; id = model->get_next_id(); *user_thread = id; parent = thread_current();