chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.88k stars 1.21k forks source link

Data race condition in boost/asio/detail/scoped_lock.hpp #837

Open dimitrov-ds opened 3 years ago

dimitrov-ds commented 3 years ago

Hi, I've just run Synopsys Coverity, version 2020.03, static analysis on Boost v 1_75_0 It has highlighted several potential issues one of which I will describe here. In scopedlock.hpp there is a mutex and a Boolean guard around the mutex. ‘locked’ is checked prior to locking and unlocking the mutex and then set to true or false respectively. This, to me and the Coverity static analysis, creates a data race condition. Is that a false positive in the static analysis tool? What am I missing? The issue can be also reproduced by running Coverity static analysis on this boost example server: https://www.boost.org/doc/libs/1_75_0/doc/html/boost_asio/example/cpp03/ssl/server.cpp

Thanks, Dimitar

gummif commented 3 years ago

Yes, lock objects are not thread safe and the bool is to check whether unlocking is needed on destruction.