title: How is ownership of mutex (lock) implemented?
body: <p>I am a little bit confused trying to implement a very simple mutex (lock) in C. I understand that a mutex is similar to a binary semaphore, except that the mutex also enforces the constraint that the thread that releases the lock, must be the same thread that most recently acquired it. I am confused on how the ownership is kept track of?</p>
  
  <p>This is what I have so far. Keep in mind that it is not completed yet, and is suppose to be really simple (uniprocessor, no recursion on mutex, disabling interrupts as mutual exclusion method, etc). </p>
  
  <pre><code>struct mutex {
      char *mutexName;
      volatile int inUse;
  };
  </code></pre>
  
  <p>I believe I should add in another member variable, i.e., whoIsOwner, but I am kind of confused as what to store there. I assume it has to be something that can uniquely identify the thread trying to call the lock? Is this correct? </p>
  
  <p>I have a thread structure in place that has a "char *threadName" member variable (along with others), but I'm not sure how I would access this from within the mutex implementation. </p>
  
  <p>Any pointers/hints/ideas would be appreciated.</p>