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

Question: How can I detach from shared_library? #66

Closed
fsmoke opened this issue Mar 29, 2024 · 2 comments
Closed

Question: How can I detach from shared_library? #66

fsmoke opened this issue Mar 29, 2024 · 2 comments

Comments

@fsmoke
Copy link

fsmoke commented Mar 29, 2024

I write custom .NET apphost application(for our project) and load into it coreclr.dll/so but this library(.NET VM) writed very tricky and not clean. They create several threads inside and there is no way to join them, so due destroying of shared_library object dtor unloads coreclr library and my app just cause access violation in random places, cos coreclr thread still alive, but code already unloaded!

I investigated original code of MS apphost - it seems there no FreeLibrary at all, so my suggession: they just left threads in the hope that system finish them and unload coreclr at the end of process.

But i don't know how make same behaviour with boost.dll - it seems shared_libarary has no any methods like detach or something like that.

PS
.net project: https://github.com/dotnet/runtime

@apolukhin
Copy link
Owner

That is a common request. However shared_library follows the std::shared_ptr design. std::shared_ptr does not have a release() function.

Have you tried something 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)

@apolukhin apolukhin closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2024
@apolukhin
Copy link
Owner

Duplicate of boostorg#68

@apolukhin apolukhin marked this as a duplicate of boostorg/dll#68 Apr 1, 2024
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