alexcrichton / curl-rust

Rust bindings to libcurl
MIT License
1.02k stars 233 forks source link

Experimental use of constructor functions to call init #334

Closed sagebind closed 4 years ago

sagebind commented 4 years ago

As mentioned in #333, this is a potentially helpful addition that ensures that curl is initialized on the main thread by using constructor functions that get called by the OS before the current program's main is called.

This has the advantage that, assuming you are on one of the supported platforms, init() will be called safely, correctly, and automatically without concerning the user about the gotchas.

This does have some disadvantages:

There's no additional runtime cost to this implementation except on platforms without a constructor, where we do an extra atomic swap that isn't necessary. This is probably fixable with additional conditional compilation.

sagebind commented 4 years ago

I removed the second atomic so it should be just as efficient as it was before now. I also went ahead and updated the documentation.

alexcrichton commented 4 years ago

👍