rem: t->state = B_THREAD_READY;
add: t->state = t->next_state = B_THREAD_READY;
context: remove_thread_from_sem(struct thread *t, struct sem_entry *sem, struct thread_queue *queue, int sem_errcode){	struct thread *t1;	// remove the thread from the queue and place it in the supplied queue	t1 = thread_dequeue_id(&sem->q, t->id);	if (t != t1)		return ERR_NOT_FOUND;	sem->count += t->sem_acquire_count;	t->state = t->next_state = B_THREAD_READY;	t->sem_errcode = sem_errcode;	thread_enqueue(t, queue);	// now see if more threads need to be woken up	while (sem->count > 0 && (t1 = thread_lookat_queue(&sem->q))) {		int delta = min(t->sem_count, sem->count);		t->sem_count -= delta;		if (t->sem_count <= 0) {			t = thread_dequeue(&sem->q);			t->state = B_THREAD_READY;			thread_enqueue(t, queue);		}		sem->count -= delta;	}	return B_NO_ERROR;}