Skip to content

Expose a non-allocating way to access the current task name. #19445

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

Closed
reem opened this issue Dec 1, 2014 · 5 comments
Closed

Expose a non-allocating way to access the current task name. #19445

reem opened this issue Dec 1, 2014 · 5 comments

Comments

@reem
Copy link
Contributor

reem commented Dec 1, 2014

Currently, std::task::name allocates a new String for the current task name, but this is unnecessary and slow.

Note: this probably requires a 'thread lifetime or a reference type specific to thread-local values, perhaps struct ThreadRef<T> { nosend: NoSend, ref: &'static T }, but I haven't really thought through all the use cases.

@thestinger
Copy link
Contributor

It needs more than that because changing the task name will invalidate it.

@reem
Copy link
Contributor Author

reem commented Dec 1, 2014

Maybe this is an appropriate use-case for dynamic borrow checking. We could return a RefCell<ThreadRef<str>>, though.... ugh.

@reem
Copy link
Contributor Author

reem commented Dec 2, 2014

Actually that would require full shared ownership, with Rc too, which would be sad for such a simple thing.

@steveklabnik
Copy link
Member

And even then, Rc boxes its contents, so it's going to end up being heap allocated anyway. Given the constaints, I'm not sure this is possible.

@reem
Copy link
Contributor Author

reem commented Feb 14, 2015

I think I have a non-allocating solution using &'static RefCell<&'static str> and some !Send impls, but it's much too complicated to be ergonomically used here. String is fine.

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

4 participants