Suppose a process is waiting for a lock held by some other process. Either it spinlocks (Busy waits) or it goes to sleep, to be woken up when the lock is released. If the waiting time is too much, it is better to sleep, since too much resources will be hogged. If the waiting time is short, the spinlocking is preferred, to avoid the overhead from sleeping and waking. Now, usually the process itself takes the decision whether to spinlock or sleep. But is there a way to make this decision from the OS?
So, the question is, is there a technique for the OS to know when a process is awaiting a lock, and if so, any efficient technique using which the OS itself decides (from how long the waiting time might be for the lock to be released) whether to allow the process to busy-wait, or to sleep the process ?