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
root@6a2e14c7eff5:~/projects/rustprj/rs-proxy/server# uname -a
Linux 6a2e14c7eff5 6.6.16-linuxkit #1 SMP Fri Feb 16 11:54:02 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux
Description
Test code is as follows, look at the code comments,thanks.
asyncfndo_work(s:&mutbool){if*s {*s = false;
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;}}#[test]fntest(){
tokio::runtime::Runtime::new().unwrap().block_on(async{
tokio::spawn(asyncmove{letmut timer = tokio::time::interval(tokio::time::Duration::from_secs(1));letmut s = true;loop{// If add this line, the timer will work properly, otherwise, not woking.// tokio::task::yield_now().await;
tokio::select! {
_= timer.tick() => {
println!("----tick");}
_ = do_work(&mut s) => {}}}}).await.unwrap();});}
I expect the second timer to output the following content every second, but it doesn't work:
-----tick
-----tick
-----tick
-----tick
-----tick
-----tick
...
The text was updated successfully, but these errors were encountered:
This seems to be a slow task poll issue again. Ref: #6315
As for this issue, although it is a multi-thread runtime, there is actually only one worker thread working, and because it is executing the above loop, no one take care of the time driver.
This code is blocking the thread because the select! always exists without yielding to the runtime. You must yield to the runtime to have reasonable behavior.
Version
Platform
Description
Test code is as follows, look at the code comments,thanks.
I expect the second timer to output the following content every second, but it doesn't work:
-----tick
-----tick
-----tick
-----tick
-----tick
-----tick
...
The text was updated successfully, but these errors were encountered: