If you trust this link, click it to continue.
https://stackoverflow.com/questions/79012177/how-use-semaphore-instead-this-codewait-with-while-loop-and-flag-linux-kernel