diff --git a/include/opendht/dht_proxy_client.h b/include/opendht/dht_proxy_client.h
index c6dbf8352590c9646698dc5efae72ecc65d40764..adeff41077d0e5c2b6661ccbd8eef38d688b57bc 100644
--- a/include/opendht/dht_proxy_client.h
+++ b/include/opendht/dht_proxy_client.h
@@ -282,7 +282,7 @@ private:
     {
         std::shared_ptr<restbed::Request> req;
         std::thread thread;
-        std::shared_ptr<bool> finished;
+        std::shared_ptr<std::atomic_bool> finished;
     };
     std::vector<Operation> operations_;
     std::mutex lockOperations_;
diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp
index d93f32bde61fa6d60ff13bea43ea3eb89160aa60..ad9e585a50e55378d12df1067d1e6dfce77ecacb 100644
--- a/src/dht_proxy_client.cpp
+++ b/src/dht_proxy_client.cpp
@@ -192,14 +192,14 @@ DhtProxyClient::get(const InfoHash& key, GetCallback cb, DoneCallback donecb,
     Query query {{}, where};
     auto filterChain = filter.chain(query.where.getFilter());
 
-    auto finished = std::make_shared<bool>(false);
+    auto finished = std::make_shared<std::atomic_bool>(false);
     Operation o;
     o.req = req;
     o.finished = finished;
     o.thread = std::thread([=](){
         // Try to contact the proxy and set the status to connected when done.
         // will change the connectivity status
-        auto ok = std::make_shared<bool>(true);
+        auto ok = std::make_shared<std::atomic_bool>(true);
         restbed::Http::async(req,
             [=](const std::shared_ptr<restbed::Request>& req,
                 const std::shared_ptr<restbed::Response>& reply) {
@@ -267,12 +267,12 @@ DhtProxyClient::put(const InfoHash& key, Sp<Value> val, DoneCallback cb, time_po
     req->set_body(body);
     req->set_header("Content-Length", std::to_string(body.size()));
 
-    auto finished = std::make_shared<bool>(false);
+    auto finished = std::make_shared<std::atomic_bool>(false);
     Operation o;
     o.req = req;
     o.finished = finished;
     o.thread = std::thread([=](){
-        auto ok = std::make_shared<bool>(true);
+        auto ok = std::make_shared<std::atomic_bool>(true);
         restbed::Http::async(req,
             [this, ok](const std::shared_ptr<restbed::Request>& /*req*/,
                         const std::shared_ptr<restbed::Response>& reply) {
@@ -426,8 +426,8 @@ DhtProxyClient::listen(const InfoHash& key, GetCallback cb, Value::Filter&& filt
             settings->set_connection_timeout(timeout); // Avoid the client to close the socket after 5 seconds.
 
             struct State {
-                bool ok {true};
-                bool cancel {false};
+                std::atomic_bool ok {true};
+                std::atomic_bool cancel {false};
             };
             auto state = std::make_shared<State>();
             restbed::Http::async(req,