title: What happens if two process in different processors try to acquire the lock at EXACTLY same time
body: <p>Ok, so I am reading about synchronization, and I read through various algorithms such as spinlocks, semaphores, and mutex to avoid race condition.</p>
  
  <p>However, these algorithms can't prevent race condition in SMP when multiple proceses access the data exactly at the same time.</p>
  
  <p>For example, suppose thread 1 in processor A runs
      lock(mutex1);
      withdraw(1000);
      unlock(mutex1);</p>
  
  <p>and thread 2 in processor B runs
      lock(mutex1);
      deposit(1000);
      deposit(1000);
      unlock(mutex1);</p>
  
  <p>When both threads run EXACTLY AT THE SAME TIME, both threads will be in critical section simultaneously.</p>
  
  <p>The only solution (should be in hardware level) would be making each processors run slightly off to each other, but it defeats the purpose of parallelism.</p>
  
  <p>Is there any hardware level support to avoid these situation where multiple processors try to acquire the lock at the exactly same time?</p>
  
  <p>(this is not a problem of atomicity, but rather problem of exact parallelism, and I wonder how SMP deals with it).</p>