/* * Create and return a new thread. Like minithread_fork, * only returned thread is not scheduled for execution. */ minithread_t* minithread_create(proc_t proc, arg_t arg) { minithread_t *mthread = (minithread_t *) malloc(sizeof(minithread_t)); if (!mthread) { return NULL; } mthread->id = minithreads_count++; mthread->level = 0; mthread->quanta = 0; mthread->base = NULL; mthread->top = NULL; minithread_allocate_stack(&mthread->base, &mthread->top); minithread_initialize_stack(&mthread->top, proc, arg, final_proc, NULL); return mthread; }
minithread_t* minithread_create(proc_t proc, arg_t arg) { minithread_t* mini = (minithread_t *) malloc(sizeof(minithread_t)); if (mini == NULL) { exit(1); //OOM } mini->thread_id = next_thread_id++; mini->quanta_count = 0; mini->level = 0; //allocate space first minithread_allocate_stack(&mini->stackbase, &mini->stacktop); //initialize basic values for minithread minithread_initialize_stack(&mini->stacktop,proc,arg,minithread_cleanup,&mini->thread_id); mini->status = NEW; return mini; }
//Create a new threads minithread_t minithread_create(proc_t proc, arg_t arg) { minithread_t new_thread = (minithread_t)malloc(sizeof(struct minithread)); if (new_thread == NULL) return NULL; new_thread->id=++last_id; new_thread->priority = PRIORITY_SHORT; minithread_allocate_stack(&(new_thread->sb), &(new_thread->sp)); minithread_initialize_stack( &(new_thread->sp), proc, arg, minithread_cleanup, NULL ); return new_thread; }
minithread_t minithread_create(proc_t proc, arg_t arg) { // Create the TCB minithread_t tcb = (minithread_t) malloc(sizeof(minithread)); // ISO C90... interrupt_level_t prev_level; // create the variables for the stack // these are **voids, b/c stack_pointer_t is a void* stack_pointer_t* stack_top = (stack_pointer_t*) malloc(sizeof(stack_pointer_t)); stack_pointer_t* stack_base = (stack_pointer_t*) malloc(sizeof(stack_pointer_t)); // Ensure this is true since we rely on this in a few lines *stack_top = NULL; *stack_base = NULL; // Initialize the TCB prev_level = set_interrupt_level(DISABLED); tcb->id = id_count++; set_interrupt_level(prev_level); tcb->priority = 0; tcb->proc = proc; tcb->arg = arg; tcb->dir_block_id = 1; // todo - make this come from the superblock tcb->open_files = hashmap_create(10, 1); // Allocate the stack minithread_allocate_stack(stack_base, stack_top); // Ensure the stack allocation succeeded if (*stack_base == NULL) return NULL; tcb->stack_base = stack_base; tcb->stack_top = stack_top; // Initialize the stack minithread_initialize_stack(stack_top, proc, arg, (proc_t) minithread_finished, (arg_t) tcb); return tcb; }
minithread_t minithread_create(proc_t proc, arg_t arg) { minithread_t new_thread = (minithread_t)malloc(sizeof(minithread)); if (new_thread == NULL){ return NULL; } semaphore_P(id_lock); new_thread->id = current_id++; semaphore_V(id_lock); new_thread->priority = 0; new_thread->rem_quanta = 1; new_thread->stackbase = NULL; new_thread->stacktop = NULL; new_thread->status = RUNNABLE; minithread_allocate_stack(&(new_thread->stackbase), &(new_thread->stacktop) ); minithread_initialize_stack(&(new_thread->stacktop), proc, arg, (proc_t)minithread_exit, NULL); return new_thread; }