Implement a spinlock to avoid spurious wakeup in threads