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

how drop rayon whren it in a dylib and dylib should be droped? #1101

Open
simline opened this issue Nov 2, 2023 · 4 comments
Open

how drop rayon whren it in a dylib and dylib should be droped? #1101

simline opened this issue Nov 2, 2023 · 4 comments

Comments

@simline
Copy link

simline commented Nov 2, 2023

load dylib in fedora using libloading, but after calling the function in dylib when there's some rayon work, dylib is not drop correctly.
When I removed all the rayon code, libloading drop dylib works fine.
What should I do?

lsof | grep 'MyLibName' always got 8(4c8t) instances

@cuviper
Copy link
Member

cuviper commented Nov 2, 2023

What target are you running on? (e.g. x86_64-unknown-linux-gnu)

@simline
Copy link
Author

simline commented Nov 2, 2023

What target are you running on? (e.g. x86_64-unknown-linux-gnu)

rustup default:stable-x86_64-unknown-linux-gnu (default)

@cuviper
Copy link
Member

cuviper commented Nov 2, 2023

OK, so with all *-linux-gnu targets, an important caveat is that glibc's dlclose doesn't do anything when there's a pending TLS destructor from that library. I don't think any of rayon's own thread_local! variables have destructors, but crossbeam-epoch does, and even the standard library has ThreadInfo that must be dropped.

I'm not sure, but it might work if you guarantee all rayon threads have completely exited before you try to unload. You can't do that at all with the global pool, and an explicit ThreadPool handle doesn't synchronize its threads on exit either (#688). I think even my suggestion there to use build_scoped might not be good enough given rust-lang/rust#116237, but a stronger version of that could collect and join all the thread handles.

But even with all that, it's possible that some code might have registered TLS destructors in non-rayon threads too, and I have no idea what could be done about that.

@cuviper
Copy link
Member

cuviper commented Nov 2, 2023

but a stronger version of that could collect and join all the thread handles.

Here's a prototype of that: master...cuviper:rayon:join-scoped

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