jeudi 31 mars 2016

C++ REST SDK: asynchronous tasks vs. C++11 multithreading

This is a conceptual question on the asynchronous task feature of the C++ REST SDK (and maybe also a bit of a noob question).

In a basic application, I have a client and perform several requests, e.g. like

http_client client(U("whatever"));

for(int i=0; i<100; ++i)
{
    http_request request;
    //fill the request
    client.request(request).then([](http_response response) { /* do something*/});
}

(The foor-loop is just to indicate that the request is sent often, I don't really use it in my code).

Questions:

  • As far I understand, the asynchronous task library then handles those incoming requests in a parallel way -- meaning that not the main thread handles all tasks in an event-like fashion, but rather the library assigns the tasks to an underlying thread pool in some (--to me intransparent--) way. Did I get that correct?

  • If the previous view is correct, then is there any reason to combine the REST SDK with the multithreading capabilities of C++. For example, taking again the above loop, start 10 threads and in each one process 10 loop iterations. Does this makes sense or is it unnecessary?

  • Moreover, in general, are there any common patterns where one should combine the ppl-capabilities by the C++11 multithreading feature? Or is it safe to rely that the REST SDK and ppl under the hood get the job done better?

(Info: I've asked this question also on the cpprest discussion page. However, this forum seems to be not maintained anymore.)

Aucun commentaire:

Enregistrer un commentaire