advance-practice/shared-state #827
Replies: 11 comments 32 replies
-
|
Beta Was this translation helpful? Give feedback.
-
有个地方不明白,Futrue 是 Pin住的,为啥还能Send到其他线程呢 |
Beta Was this translation helpful? Give feedback.
-
请问,这个”跨“字应该怎么理解?代码中,db也是给了多个process().await用,我理解这里也应该也是”跨“ |
Beta Was this translation helpful? Give feedback.
-
use std::sync::Mutex;
struct CanIncrement {
mutex: Mutex<i32>,
}
impl CanIncrement {
// 该方法不是 `async`
fn increment(&self) {
let mut lock = self.mutex.lock().unwrap();
*lock += 1;
}
}
async fn increment_and_do_stuff(can_incr: &CanIncrement) {
can_incr.increment();
do_something_async().await;
} 文章中的这个例子可以通过编译,是因为只需要在 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
反馈一个语句不顺的小问题: |
Beta Was this translation helpful? Give feedback.
-
新人问一下这里为什么不用hashmap包裹锁,例如 |
Beta Was this translation helpful? Give feedback.
-
process() 函数,使用std::sync::Mutex,同时在db.lock().unwrap() 获取锁后,还有await操作: connection.write_frame(&response).await.unwrap(); ,这代码可能会出现死锁的问题吧 |
Beta Was this translation helpful? Give feedback.
-
邮件已收到!我会尽快处理的,请耐心等待。
|
Beta Was this translation helpful? Give feedback.
-
理解了“锁如果在多个 .await 过程中持有” 的意思。就是在锁的生命周期内,锁还没结束,不能再次.await。
解决办法就两个:
|
Beta Was this translation helpful? Give feedback.
-
邮件已收到!我会尽快处理的,请耐心等待。
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
advance-practice/shared-state
https://course.rs/async-rust/tokio/shared-state.html
Beta Was this translation helpful? Give feedback.
All reactions