You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes it can be useful to break up longer execution into smaller parts. As a general rule task::blocking fills that role for us (#251). But std has another method for smoothing out load within threads: thread::yield_now. This function hints to the OS-scheduler that it's ready to yield for a while so other work can resume, improving tail-latency.
When dealing with longer-running tasks, especially with task::blocking, it can make sense to occasionally pro-actively yield control back to schedulers. This can help with throughput, especially if there we're hitting upper limits on system resources (e.g. CPU, threads).
Implementation
I'm imagining inside task::blocking we'd wrap thread::yield_now inside a future to let other threads run on-cpu instead.
Inside task::spawn / task::block_on this would re-schedule the current task on the futures executor. In general this seems less important than the task::blocking use, but it might still come in useful, and overall it seems good to still let it do more or less what you'd expect it to.
The signature would be:
asyncfnyield_now();
Example
asyncfnmain(){let a = task::spawn(async{println!("hello world");});
task::yield_now();
a.await;}
The text was updated successfully, but these errors were encountered:
Motivation
Sometimes it can be useful to break up longer execution into smaller parts. As a general rule
task::blocking
fills that role for us (#251). But std has another method for smoothing out load within threads:thread::yield_now
. This function hints to the OS-scheduler that it's ready to yield for a while so other work can resume, improving tail-latency.When dealing with longer-running tasks, especially with
task::blocking
, it can make sense to occasionally pro-actively yield control back to schedulers. This can help with throughput, especially if there we're hitting upper limits on system resources (e.g. CPU, threads).Implementation
I'm imagining inside
task::blocking
we'd wrapthread::yield_now
inside a future to let other threads run on-cpu instead.Inside
task::spawn
/task::block_on
this would re-schedule the current task on the futures executor. In general this seems less important than thetask::blocking
use, but it might still come in useful, and overall it seems good to still let it do more or less what you'd expect it to.The signature would be:
Example
The text was updated successfully, but these errors were encountered: