开发者

pthread_mutex_lock return not tested

I'm really wondering why all source codes that implement a pthread_mutex_lock never test its return value as defined :

documentation of pthread

even in books the examples don't test if the lock is in error, codes 开发者_如何学Gojust do the lock.

Is there any reason I missed to let it untested ?


Basically, the only “interesting” error is EINVAL, which in most programs will only happen because of memory corruption, or, as I know from my own painful experience, during program shutdown after destructors have already destroyed some mutexes. The way I see it, the only reasonable response to such an error is to abort the program, which on the other hand is very inconvenient if the errors occur precisely because the program is already shutting down. Of course, this can be solved, but it’s not at all that simple, and not much is gained by it for most programs.


First off, I think "all source code" and "never test" are too strong. I think "some" and "often" would be more accurate.

In books, error checking code is often omitted for clarity of exposition.

As to real-world code, I guess the answer has to be that it is perceived that the likelihood of failure is very low. Whether this is a good assumption is debatable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜