-
Notifications
You must be signed in to change notification settings - Fork 542
Add yield_now
and yield_local
#1026
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
Conversation
Is there some peripheral motivation for using |
We already use |
Mainly usability, e.g. But something like |
(So one reason to avoid all this was laziness.. 😅 ) |
I'd also argue that This would lead me personally to something like #[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Yielded {
ExecutedJob,
NoJobFound,
} which tries to be sufficiently short and pick up the
I'd say that since |
We do speak of "jobs" in docs a lot, or "work", but the only thing I found in a public API name was "tasks" in (It would probably be nice if we were more consistent in docs, but it's not a breaking change to clean that up later.) |
Personally, I am perfectly happy with the current state as it is certainly much more expressive than |
Thank you for your feedback! And since you've shown interest, I would also love to hear if you're thinking about concrete use-cases for this. |
I have to admit that this was a "accidental review" out of curiosity. While I have had my run-ins with Personally, I would even go as far as calling such an API a bit "unrayonic" meaning that I go for Rayon precisely in those cases where I do not want to worry about thread scheduling and task placement but just want my data to be distributed to the available CPU without manual intervention. And while I have written synchronization involving But of course, other reporters do seem to have these requirements as per #548. Sorry for not being able to shed more on these use cases. |
No worries, "I wouldn't use this" is valid feedback as well, thanks! |
I'm going ahead with this. The rough idea is something folks have asked for in the past, and even if it turns out unused, I don't think it will present much of a maintenance burden. @bors r+ |
Wrong bot... bors r+ |
yield_now
looks for work anywhere in the thread pool and executes it.yield_local
only looks in the thread-local deque (including broadcasts).In either case, they return:
Some(Yield::Executed)
if work was found and executed.Some(Yield::Idle)
if no work was found in their pool/thread.None
if the current thread is not part of a thread pool.These do not call
std::thread::yield_now()
, but the docs suggest polling loops might want to add that as a fallback.