rem: team->death_sem = create_sem(0, death_sem_name); if (team->death_sem < 0)
add: deathSem = create_sem(0, death_sem_name); if (deathSem < 0)
context: team_delete_team(struct team *team){	team_id teamID = team->id;	port_id debuggerPort = -1;	if (team->num_threads > 0) {		// there are other threads still in this team,		// cycle through and signal kill on each of the threads		// ToDo: this can be optimized. There's got to be a better solution.		struct thread *temp_thread;		char death_sem_name[B_OS_NAME_LENGTH];		cpu_status state;		sprintf(death_sem_name, "team %ld death sem", team->id);		team->death_sem = create_sem(0, death_sem_name);		if (team->death_sem < 0)			panic("thread_exit: cannot init death sem for team %ld\n", team->id);		state = disable_interrupts();		GRAB_TEAM_LOCK();		// If the team was being debugged, that will stop with the termination		// of the nub thread. The team structure has already been removed from		// the team hash table at this point, so noone can install a debugger		// anymore. We fetch the debugger's port to send it a message at the		// bitter end.		GRAB_TEAM_DEBUG_INFO_LOCK(team->debug_info);		if (team->debug_info.flags & B_TEAM_DEBUG_DEBUGGER_INSTALLED)			debuggerPort = team->debug_info.debugger_port;		RELEASE_TEAM_DEBUG_INFO_LOCK(team->debug_info);		// we can safely walk the list because of the lock. no new threads can be created		// because of the TEAM_STATE_DEATH flag on the team		temp_thread = team->thread_list;		while (temp_thread) {			struct thread *next = temp_thread->team_next;			send_signal_etc(temp_thread->id, SIGKILLTHR, B_DO_NOT_RESCHEDULE);			temp_thread = next;		}		// If someone is waiting for this team to be loaded, but it dies		// unexpectedly before being done, we need to notify the waiting		// thread now.		if (team->loading_info) {			// there's indeed someone waiting			struct team_loading_info *loadingInfo = team->loading_info;			team->loading_info = NULL;			loadingInfo->result = B_ERROR;			loadingInfo->done = true;			GRAB_THREAD_LOCK();			// wake up the waiting thread			if (loadingInfo->thread->state == B_THREAD_SUSPENDED) {				loadingInfo->thread->state = B_THREAD_READY;				loadingInfo->thread->next_state = B_THREAD_READY;				scheduler_enqueue_in_run_queue(loadingInfo->thread);			}			RELEASE_THREAD_LOCK();		}		RELEASE_TEAM_LOCK();		restore_interrupts(state);		// wait until all threads in team are dead.		acquire_sem_etc(team->death_sem, team->num_threads, 0, 0);		delete_sem(team->death_sem);	}	// free team resources	vm_delete_aspace(team->aspace);	delete_owned_ports(team->id);	sem_delete_owned_sems(team->id);	remove_images(team);	vfs_free_io_context(team->io_context);	free(team);	// notify the debugger, that the team is gone	user_debug_team_deleted(teamID, debuggerPort);}