Mutual Exclusion Locks

Syntax

A mutual exclusion lock is a special case of a semaphore when the initial value is 1. The type of a lock is mutex_t. A lock must be initialized with mutex_init() before its use. Then, a lock can be acquired with mutex_lock() and then released with mutex_unlock(). All mutex lock related functions start with mutex_. The specification of these functions are shown below:

#include  <synch.h>

mutex_t   Lock;

int  mutex_init(
          mutex_t  *Lock,   /* pointer to a lock */
          USYNC_THREAD,     /* use this in CS270 */
          (void *) NULL);   /* always use this   */


int  mutex_lock(
          mutex_t  *Lock);  /* pointer to a lock */


int  mutex_unlock(
          mutex_t  *Lock);  /* pointer to a lock */