X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=threads.cc;h=399472c9ac60b5b578ea0af88ea05bcf7da06c9f;hb=5e3720f6a6dccf2af670e4ab30660130f2a57c8f;hp=0ed7bdcabc084eabf0755c8df098b724d3c023c4;hpb=c441974826572b713174c571104bdf9bd37c018b;p=model-checker.git diff --git a/threads.cc b/threads.cc index 0ed7bdc..399472c 100644 --- a/threads.cc +++ b/threads.cc @@ -1,4 +1,7 @@ -/* -*- Mode: C; indent-tabs-mode: t -*- */ +/** @file threads.cc + * @brief Thread functions. + */ + #include "libthreads.h" #include "common.h" @@ -11,23 +14,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 + * @todo We should make the START event always immediately follow the + * CREATE event, so we don't get redundant traces... + */ void thread_startup() { - Thread * curr_thread=thread_current(); + Thread * curr_thread = thread_current(); + + /* 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); } @@ -45,7 +60,7 @@ int Thread::create_context() context.uc_stack.ss_size = STACK_SIZE; context.uc_stack.ss_flags = 0; context.uc_link = model->get_system_context(); - makecontext(&context, start_routine, 1); + makecontext(&context, thread_startup, 0); return 0; } @@ -70,19 +85,20 @@ void Thread::complete() } } -Thread::Thread(thrd_t *t, void (*func)(), 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();