title: How to implement a spinlock to avoid blocking
body: <p>Consider the following code:</p>
  
  <pre><code>// Below block executed by thread t1
  synchronized(obj) {
     obj.wait(0);
  }
  
  // This block executed by thread t2
  synchronized(obj) {
      obj.notify();
  }
  </code></pre>
  
  <p>I understand that in above code if <code>t1</code> has taken ownership of synchronized block and at the same time if thread <code>t2</code> tries to take synchronized block, then <code>t2</code> goes for a kernel wait.
  I want to avoid this situation and spin <code>t2</code> before the block until <code>t1</code> calls wait and leaves ownership of the block. Is that possible?</p>