For example I have a resource lock.
So a multithreaded function checks if it’s set before accessing a resource, then if it’s not sets it
Is there a tiny possibility that between checking and setting, another thread would have set the same lock?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Depends how you want it to work. Read the man page for mutex_lock. The checking whether a lock is set is superfluous in this case, since the very act of setting the mutex pauses the thread until the mutex is available (and so any sort of
if(resource_unavailable) { wait for availability }code becomes unnecessary).