vendredi 1 avril 2016

C++ using standard library synchronization tools with the C++ REST SDK

When using the asynchronous tasks from the C++ REST SDK, is it possible to apply synchronization tools from the multithreading standard library? Example:

http_client client(U("whatever"));
http_request request;

int i = 0;
client.request(request).then([&i](http_response response) { i = 1;});
//here use variable i

The above code obviously introduces a race condition, which in principle could be cured by using a std::mutex or std::atomic. Is this possible, i.e. does the underlying asynchronous task implementation respect this mutex? And if it is possible, is it so in a platform-independent way?

Aucun commentaire:

Enregistrer un commentaire