Pthread_mutex_lock return not checked

I'm really curious why all the source codes that implement pthread_mutex_lock never check its return value as defined:

pthread documentation

even in books, examples do not check if locking is an error; codes simply block.

Is there any reason why I missed it so that it is not tested?

+7
source share
2 answers

In principle, the only โ€œinterestingโ€ error is EINVAL , which in most programs will only happen due to memory corruption or, as I know because of my own painful experience, during program shutdown after the destructors have already destroyed some mutexes. The way I see it, the only reasonable answer to such an error is to interrupt the program, which, on the other hand, is very inconvenient if errors occur precisely because the program is already closing. Of course, this can be solved, but it is not so simple and not so much for him for most programs.

+3
source

Firstly, I think that "all source" and "never tested" are too strong. I think "some" and "often" would be more accurate.

In books, the verification error code is often skipped for clarity.

Regarding the real code, I believe that the answer should be that it is believed that the probability of failure is very low. Whether this is a good guess is controversial.

+1
source

All Articles