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