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

Thread.current is unnecessarily noasync #5139

Open
weissi opened this issue Nov 29, 2024 · 2 comments
Open

Thread.current is unnecessarily noasync #5139

weissi opened this issue Nov 29, 2024 · 2 comments
Assignees

Comments

@weissi
Copy link
Contributor

weissi commented Nov 29, 2024

Thread.current is very useful as a debugging mechanism to understand the ordering of code running concurrently and/or in parallel. This is very useful to use from async functions.

Sure, the workaround is just

extension Thread {
    public static var currentThread: Thread {
        return Thread.current
    }
}

but that shouldn't be necessary.

@parkera
Copy link
Contributor

parkera commented Dec 2, 2024

Maybe it's useful for debugging, but it's wrong to conflate a task with a thread. Making this API available in async contexts seems like a mistake to me. @phausler did the original audit, though, so pulling him in for his opinion.

@weissi
Copy link
Contributor Author

weissi commented Dec 2, 2024

Maybe it's useful for debugging, but it's wrong to conflate a task with a thread. Making this API available in async contexts seems like a mistake to me. @phausler did the original audit, though, so pulling him in for his opinion.

Sure, it's important to not conflate tasks & threads, just like it was always important to not conflate DispatchQueues and threads. And yet we didn't try to ban you calling Thread.current from a DispatchQueue. And it's really important for debugging (and sometimes even when logging around problematic sections).

Also: Allowing it anywhere doesn't cause any hard, we're using it anyway but today we have to work around it (with that extension Thread)

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

3 participants