libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.29k stars 903 forks source link

Use std::call_once instead of double-checked locking in singletons #1042

Closed bllanos closed 2 months ago

bllanos commented 2 months ago

Fixes #1041

Notes

I added an assertion to the ExitInstance() function to help users detect if they call it multiple times in the same program by accident. Correct me if I am mistaken, but I assumed singleton classes do not need to be initialized and shutdown more than once. The previous version of the code allowed for multiple cycles of initialization and shutdown.

Other

The CONTRIBUTING.md file mentions format-check.sh that I don't see in the repository, and it also links to a different location for the repository, https://github.com/whoshuu/cpr.

COM8 commented 2 months ago

On your note: No, I'm not aware of any case where we use the singleton being initialized and destroyed multiple times. (Isn't this a bit against what a singleton is - in theory?).

Arg, yes the contribution docs. We've started rewriting them and extending them over here but yeah. There is room for improvement.