<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>async on 便利屋68 の home page</title><link>https://rikaaa0928.github.io/tags/async/</link><description>Recent content in async on 便利屋68 の home page</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Sun, 27 Oct 2024 19:15:00 +0800</lastBuildDate><atom:link href="https://rikaaa0928.github.io/tags/async/index.xml" rel="self" type="application/rss+xml"/><item><title>Rust tokio: Send与Sync</title><link>https://rikaaa0928.github.io/posts/rust-tokio-learn-send-sync/</link><pubDate>Sun, 27 Oct 2024 19:15:00 +0800</pubDate><guid>https://rikaaa0928.github.io/posts/rust-tokio-learn-send-sync/</guid><description>tokio中，返回的future无脑实现Send，因为tokio异步框架并不能保证单个异步任务绑定某个真实线程执行，实现Send表示这个future可以安全的跨线程执行。
Sync表示并发安全，需要跨异步任务调用的必须是Sync，可以套Mutex实现非Sync转Sync，再套Arc实现clone。
// Sync 类型:
Arc // 当 T: Sync
Mutex // 当 T: Send
RwLock // 当 T: Send
AtomicBool
AtomicI32
Vec // 当 T: Sync
String
&amp;amp;T // 当 T: Sync
// 非 Sync 类型:
RefCell // 内部可变性不是线程安全的
Cell // 同上
Rc // 引用计数不是线程安全的
*mut T // 裸指针</description></item></channel></rss>