c - How to check if a mutex is not acquired? -
I want to see that the Mute X is free and is not available.
I did
Pthread_mutex_trylock (mutex_object);
but it returns a What if Mute X was not acquired? Does it return a price for it? pthread_mutex_trylock does not return "- 1 error for" this "code Returns an 'error' code with potential values in "errno.h". One of these, Note that for returning mutes, the return value of 0 does not distinguish between the case where the mute was previously unlocked, and in that case where the calling thread was already owned by any In case, if 0 if Mute X is acquired and for the
-1 error
EBUSY , means that another thread is already the owner of the lock
pthread_mutex_trylock , you should not see any other error code, as long as your program There should not be a serious bug.
pthread_mutex_trylock 0 returns, you are responsible for unlocking it via
pthread_mutex_unlock , because you have become the owner (or, in the recurring case, Your lock number increases 1) On the successful
pthread_mutex_trylock
Comments
Post a Comment