Ejemplo n.º 1
0
void blockUntilComplete() {
  // TODO
  queue_enqueue(&prq,uthread_self());   
  uthread_block();                       //block the thread while it is reading 
 
  
}
Ejemplo n.º 2
0
/*
 * uthread_mtx_lock
 *
 * Lock the mutex.  This call will block if it's already locked.  When the
 * thread wakes up from waiting, it should own the mutex (see _unlock()).
 */
void
uthread_mtx_lock(uthread_mtx_t *mtx)
{
	//NOT_YET_IMPLEMENTED("UTHREADS: uthread_mtx_lock");
        assert(mtx != NULL);
        if(mtx -> m_owner == NULL)
            mtx -> m_owner = ut_curthr;
        else{
            assert(mtx->m_owner != ut_curthr);
            //put current thread in the waiters queue
            utqueue_enqueue(&mtx->m_waiters, ut_curthr);
            //block current thread
            uthread_block();
        }
}
Ejemplo n.º 3
0
/*
 * uthread_cond_wait
 *
 * Should behave just like a stripped down version of pthread_cond_wait.
 * Block on the given condition variable.
 * param cond: the pointer to the conditional variable object
 * param mtx: the pointer to the mutex object
 */
void
uthread_cond_wait(uthread_cond_t *cond, uthread_mtx_t *mtx)
{
	/* Make sure the mtx is locked by the current thread */

	assert(mtx != NULL && cond != NULL);
	assert(mtx->m_owner == ut_curthr);
	

	utqueue_enqueue(&cond->uc_waiters, ut_curthr);
	uthread_mtx_unlock(mtx);

	/* Block on the conditional variable */
	uthread_block();

	/* Now it gets back, try lock the mutex */
	uthread_mtx_lock(mtx);
}