Skip to content

Commit a47ef1d

Browse files
authored
Merge pull request #42 from libcpr/feature/session_thread_safety
cpr::Session Thread Safety Information
2 parents 7138a18 + af8ec9f commit a47ef1d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

advanced-usage.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ cpr::Response response = session.Complete(curl_result);
251251
```
252252
{% endraw %}
253253
254+
### Thread Safety
255+
256+
A `cpr::Session` object by default is not thread safe, meaning you are not allowed to set multiple options (e.g. `SetBody(..)`, `SetHeader(..)`) in parallel.
257+
Preparing and executing a web request needs to be done sequentially, but not single threaded.
258+
259+
To further exploit parallelism and take advantage of reusing `cpr::Session` objects take a look at the asynchronous `cpr::Session` interface (e.g. `cpr::AsyncResponse asyncResponse = session.GetAsync();`).
260+
Internally `cpr::ThreadPool` gets used for this, handling all requests (Ref: [Asynchronous Requests](#asynchronous-requests)).
261+
262+
254263
## HTTP Compression
255264
256265
HTTP compression is a capability that can improve transfer speed and bandwidth utilization between web servers and web clients.

0 commit comments

Comments
 (0)