Closed bansan85 closed 2 years ago
Could you provide some addtional detail regarding the error that is caused?
Considers these 3 lines:
restbed::Service service_;
std::thread server([&service_]() { service_.start(settings); });
while (!service_.is_up()){}
The function is_up
is used to know when the service has started.
The data race occurs when the function start
ends :
start
writes m_uptime
.is_up
reads m_uptime
.It's not really a critical bug but a thread sanitizer will complain about this undefined behavior.
Thanks for catching this issue. Sorry for the delay.
In service, the field
m_uptime
should be thread-safe.I started a service in a thread. In another thread I checked if service
is_up
.I may have a data race : when service is up, the service write in
m_uptime
and the other thread may readm_uptime
viais_up
.The solution is not perfect. In
get_uptime
, the service could be down betweenis_down
and the read of the value but it's better than nothing and avoid the use of mutex.