title: How costly is a low contention mutex in terms of cpu
body: <p>I have some C code (on Linux) that needs to run in a thread safe manner. It's very low contention but I have to guard it to ensure correctness.</p>
  
  <p>I have the option of using local variables to guard it (which will work based on how the code is written) but since I have a mutex variable, which is the better approach in terms of cpu usage?</p>
  
  <p>As I expect nearly never to have any contention on the lock is acquiring and releasing mutex significantly more costly compared to checking, incrementing and decrementing a local variable ?</p>
  
  <p>I use the mutex elsewhere so by not using it I am not saving any memory.</p>