How to lock access to shared resource in 2 threads.

What should I do with IsUnlocked()?
Do I keep calling it till it returns true? Or do I sleep?
Or does it wait automatically till it’s true?