Is there a bug in the boost asio HTTP Server 3 example or boost bug?

爷,独闯天下 提交于 2019-11-29 15:46:55

The HTTP Server 3 example uses a pool of threads. And while Valgrind is an immensely useful suite of programs, using it correctly requires a bit of tact. As the helgrind documentation states, it is best to start using helgrind early in a project. Throwing an existing multi-threaded program at helgrind is very likely to report many false positives in my experience. As an example, helgrind cannot always detect data races when using posix condition variables, this quote is from the helgrind documentation I linked previously

Avoid POSIX condition variables. If you can, use POSIX semaphores (sem_t, sem_post, sem_wait) to do inter-thread event signalling. Semaphores with an initial value of zero are particularly useful for this.

It is possible this is the cause of the false positives you have cited. Both the Asio and Thread libraries use condition variables as part of their implementation. I very much doubt the possible data races or incorrect lock ordering is due to a bug in either library. It's worth quoting Jeff Atwood's First Rule of Programming here

An essential part of being a humble programmer is realizing that whenever there's a problem with the code you've written, it's always your fault. It is possible that a bug exists in the OS, the compiler, or a third-party product -- but this should not be your first thought. It is much more likely that the bug exists in the application code under development.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!