Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shared_library::release() #68

Open
manipuladordedados opened this issue Feb 16, 2024 · 2 comments
Open

Add shared_library::release() #68

manipuladordedados opened this issue Feb 16, 2024 · 2 comments

Comments

@manipuladordedados
Copy link

Some plugins are never safe to unload (e.g. if you're using Qt, Qt will start threads that are never joined and register thread-local variables in other threads, and it's unsafe to unload Qt code then). I'd like to use Boost.DLL for its portable API, but right now I need to use code like this to provoke an intentional leak:

auto lib = new dll::shared_library;
// ...

Here's code in the wild making use of this workaround: https://gitlab.com/emilua/qt6/-/blob/23baacf56b79d8355082df97bd1d0c2fa6c64ec1/src/qt_handle.cpp#L25

I'd rather do something like this:

dll::shared_library lib;
// ...
lib.release();

Can we have the release() function for shared_library?

@manipuladordedados manipuladordedados changed the title Some plugins are never safe to unload Add shared_library::release() Feb 17, 2024
@apolukhin
Copy link
Member

apolukhin commented Feb 19, 2024

shared_library follows the std::shared_ptr design. std::shared_ptr does not have a release() function.

Have you tried sokething like this:

std::vector<shared_library>& no_unload_registry() {
    static std::vector<shared_library> reg;
    return reg;
}

When there's a need to load library that does not unload till the end of program, do no_unload_registry().emplace_back(parameters_for_shared_library)

@manipuladordedados
Copy link
Author

shared_library follows the std::shared_ptr design. std::shared_ptr does not have a release() function.

Maybe the solution here should be different then. shared_ptr does allow one to customize the destructor, and you can even use a no-op closure here. What about something similar? Maybe load_mode::dont_unload?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants