rem: t->priority = THREAD_IDLE_PRIORITY; t->state = THREAD_STATE_RUNNING; t->next_state = THREAD_STATE_READY;
add: t->priority = B_IDLE_PRIORITY; t->state = B_THREAD_RUNNING; t->next_state = B_THREAD_READY;
context: int thread_init(kernel_args *ka){	struct thread *t;	unsigned int i;//	dprintf("thread_init: entry\n");	// create the thread hash table	thread_hash = hash_init(15, (addr)&t->all_next - (addr)t,		&thread_struct_compare, &thread_struct_hash);	// zero out the run queues	memset(run_q, 0, sizeof(run_q));	// zero out the dead thread structure q	memset(&dead_q, 0, sizeof(dead_q));	// allocate a snooze sem	snooze_sem = create_sem(0, "snooze sem");	if(snooze_sem < 0) {		panic("error creating snooze sem\n");		return snooze_sem;	}	// create an idle thread for each cpu	for(i=0; i<ka->num_cpus; i++) {		char temp[64];		vm_region *region;		sprintf(temp, "idle_thread%d", i);		t = create_thread_struct(temp);		if(t == NULL) {			panic("error creating idle thread struct\n");			return ENOMEM;		}		t->team = team_get_kernel_team();		t->priority = THREAD_IDLE_PRIORITY;		t->state = THREAD_STATE_RUNNING;		t->next_state = THREAD_STATE_READY;		sprintf(temp, "idle_thread%d_kstack", i);		t->kernel_stack_region_id = vm_find_region_by_name(vm_get_kernel_aspace_id(), temp);		region = vm_get_region_by_id(t->kernel_stack_region_id);		if(!region) {			panic("error finding idle kstack region\n");		}		t->kernel_stack_base = region->base;		vm_put_region(region);		hash_insert(thread_hash, t);		insert_thread_into_team(t->team, t);		idle_threads[i] = t;		if(i == 0)			arch_thread_set_current_thread(t);		t->cpu = &cpu[i];	}	// create a set of death stacks	num_death_stacks = smp_get_num_cpus();	if(num_death_stacks > 8*sizeof(death_stack_bitmap)) {		/*		 * clamp values for really beefy machines		 */		num_death_stacks = 8*sizeof(death_stack_bitmap);	}	death_stack_bitmap = 0;	death_stacks = (struct death_stack *)kmalloc(num_death_stacks * sizeof(struct death_stack));	if(death_stacks == NULL) {		panic("error creating death stacks\n");		return ENOMEM;	}	{		char temp[64];		for(i=0; i<num_death_stacks; i++) {			sprintf(temp, "death_stack%d", i);			death_stacks[i].rid = vm_create_anonymous_region(vm_get_kernel_aspace_id(), temp,				(void **)&death_stacks[i].address,				REGION_ADDR_ANY_ADDRESS, KSTACK_SIZE, REGION_WIRING_WIRED, LOCK_RW|LOCK_KERNEL);			if(death_stacks[i].rid < 0) {				panic("error creating death stacks\n");				return death_stacks[i].rid;			}			death_stacks[i].in_use = false;		}	}	death_stack_sem = create_sem(num_death_stacks, "death_stack_noavail_sem");	// set up some debugger commands	add_debugger_command("threads", &dump_thread_list, "list all threads");	add_debugger_command("thread", &dump_thread_info, "list info about a particular thread");	add_debugger_command("next_q", &dump_next_thread_in_q, "dump the next thread in the queue of last thread viewed");	add_debugger_command("next_all", &dump_next_thread_in_all_list, "dump the next thread in the global list of the last thread viewed");	add_debugger_command("next_team", &dump_next_thread_in_team, "dump the next thread in the team of the last thread viewed");	return 0;}