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 0 if Mute X is acquired and for the -1 error

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, 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.

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 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

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -