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

Dropping Value in TLS #37

Closed
nemosupremo opened this issue May 31, 2022 · 1 comment
Closed

Dropping Value in TLS #37

nemosupremo opened this issue May 31, 2022 · 1 comment

Comments

@nemosupremo
Copy link

I'm trying to figure out how to do this - my problem is I have a TLS that contains some database connections that are live for the duration of the thread. What I would like do is, when the thread is being destroyed, take the value out of TLS so I can drop it (otherwise, the value just lives forever in TLS and is never cleaned up).

The only thing that seems to work is Mutex<Option<T>>, but reaching for a Mutex here seems like overkill. RefCell/Rc doesn't work because of the Send requirement. Anything I might be overlooking here?

@nemosupremo
Copy link
Author

Actually looks like I can get what I want with ThreadLocal<UnsafeCell<Option<T>>>.

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

1 participant