在锁定互斥体之后,我不能放置一个异步函数.例2可行,而例1行得通.为什么会这样呢.我已经处理过临时工了,为什么会出问题?
let temp = Arc::new(Mutex::new(0));
tokio::spawn(async move {
let temp = temp.lock().unwrap();
drop(temp);
async_func().await
});
tokio::spawn(async move {
async_func().await;
let temp = temp.lock().unwrap();
drop(temp);
});
future cannot be sent between threads safely future created by async block is not `Send` Help: within `impl futures_util::Future<Output = ()>`, the trait `std::marker::Send` is not implemented for `std::sync::MutexGuard<'_, i32>` Note: future is not `Send` as this value is used across an await Note: required by a bound in `tokio::spawn