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

util: Support to have shared local data on LocalPoolHandle #4642

Closed
wants to merge 4 commits into from

Conversation

nkzawa
Copy link

@nkzawa nkzawa commented Apr 28, 2022

Motivation

Currently, there is no way to have shared thread-local data. It's required when data accessed from tasks is !Send.
This is useful for stateful applications like a game server, or when you want to have like per-thread cache.

Solution

Allow having shared local data. Also, add the spawn_pinned_at method which works the same with spawn_pinned except you can specify which worker thread the task is spawned.

I tried to make it a minimum, but it's a breaking change, unfortunately.

@Darksonn Darksonn added A-tokio-util Area: The tokio-util crate M-task Module: tokio/task S-breaking-change A breaking change that requires manual coordination to be released. labels Apr 28, 2022
@Darksonn
Copy link
Contributor

I will review this next time we make a breaking release of tokio-util.

@nkzawa
Copy link
Author

nkzawa commented Apr 30, 2022

Didn't know that but just found the std::thread_local! macro exists. In that case, seems only a method to spawn onto a specific thread is necessary, and it'll not be a breaking change any more. I will change like that if it's preferable.

EDIT:
Seems there are some disadvantages with thread_loca! like the behavior of destruction, and it cannot have generics.
The library https://crates.io/crates/thread_local requires the data to be Send

@Darksonn
Copy link
Contributor

Darksonn commented Jun 1, 2022

I'm going to close this because I don't think we want this. You can implement the feature yourself using Rc or thread_local!.

The ability to spawn on a specific thread will be added by #4680.

@Darksonn Darksonn closed this Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate M-task Module: tokio/task S-breaking-change A breaking change that requires manual coordination to be released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants