I think that's your answer. A mutex error return probably indicates an application bug, such as double unlock. You should probably assert or abort on "can't happen" mutex errors.
Programmers are lazy. If they take the time to document an error return value, then you should probably heed their warnings. :)
#ifdef NDEBUG
# define VERIFY(x) ((x), 1)
#else
# define VERIFY(x) assert((x))
#endif
Then you can write VERIFY(pthread_mutex_unlock(&lock) == 0);
You don't need, however, to consider the possibility of your program continuing to run after pthread_mutex_unlock fails.Your code could just as well be written as
assert(pthread_mutex_unlock(&lock) == 0);
which of course has the added benefit of not inventing anything new, i.e. being standard and immediately understood by anyone who knows the language and its libraries reasonably well.Of course not unlocking the mutex in non-debug builds would be a problem.
Thanks, and sorry.
Be careful about "can't possibly fail".
1. stop everything
2. coredump (if applicable)
3. return -1 from main
"I was wrong about why malloc finally failed! @GodmarBack observes, in the comments, that x64 systems only have an address space of 48 bits, which comes out to about 131000 GB. So, on my machine at least, the malloc finally failed because of address space exhaustion."