<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>4 陷阱 on 编程那些事儿</title><link>https://before80.github.io/prgms/Rust/comprehensiveRust/concurrency-afternoon/async-pitfalls/</link><description>Recent content in 4 陷阱 on 编程那些事儿</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Tue, 11 Aug 2026 23:57:44 +0800</lastBuildDate><atom:link href="https://before80.github.io/prgms/Rust/comprehensiveRust/concurrency-afternoon/async-pitfalls/index.xml" rel="self" type="application/rss+xml"/><item><title>4.1 阻塞执行器</title><link>https://before80.github.io/prgms/Rust/comprehensiveRust/concurrency-afternoon/async-pitfalls/01-blocking-executor/</link><pubDate>Tue, 11 Aug 2026 11:30:00 +0800</pubDate><guid>https://before80.github.io/prgms/Rust/comprehensiveRust/concurrency-afternoon/async-pitfalls/01-blocking-executor/</guid><description>&lt;blockquote&gt;
&lt;p&gt;译文 · 基于 &lt;a href="https://google.github.io/comprehensive-rust/"&gt;Comprehensive Rust&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://google.github.io/comprehensive-rust/concurrency/async-pitfalls/blocking-executor.html"&gt;https://google.github.io/comprehensive-rust/concurrency/async-pitfalls/blocking-executor.html&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="41-阻塞执行器"&gt;4.1 阻塞执行器&lt;/h1&gt;
&lt;p&gt;多数异步运行时只允许 I/O 任务并发运行。这意味着 CPU 阻塞任务会阻塞执行器，并阻止其他任务执行。简便的变通办法是尽可能使用异步等价方法。&lt;/p&gt;</description></item><item><title>4.2 `Pin`</title><link>https://before80.github.io/prgms/Rust/comprehensiveRust/concurrency-afternoon/async-pitfalls/02-pin/</link><pubDate>Tue, 11 Aug 2026 11:30:00 +0800</pubDate><guid>https://before80.github.io/prgms/Rust/comprehensiveRust/concurrency-afternoon/async-pitfalls/02-pin/</guid><description>&lt;blockquote&gt;
&lt;p&gt;译文 · 基于 &lt;a href="https://google.github.io/comprehensive-rust/"&gt;Comprehensive Rust&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://google.github.io/comprehensive-rust/concurrency/async-pitfalls/pin.html"&gt;https://google.github.io/comprehensive-rust/concurrency/async-pitfalls/pin.html&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="42-pin"&gt;4.2 &lt;code&gt;Pin&lt;/code&gt;&lt;/h1&gt;
&lt;p&gt;回想一下：async 函数或块会创建一个实现 &lt;code&gt;Future&lt;/code&gt; 并包含所有局部变量的类型。其中一些变量可能持有指向其他局部变量的引用（指针）。为确保这些引用保持有效，该 future 绝不能被移动到不同的内存位置。&lt;/p&gt;</description></item><item><title>4.3 异步 Trait</title><link>https://before80.github.io/prgms/Rust/comprehensiveRust/concurrency-afternoon/async-pitfalls/03-async-traits/</link><pubDate>Tue, 11 Aug 2026 11:30:00 +0800</pubDate><guid>https://before80.github.io/prgms/Rust/comprehensiveRust/concurrency-afternoon/async-pitfalls/03-async-traits/</guid><description>&lt;blockquote&gt;
&lt;p&gt;译文 · 基于 &lt;a href="https://google.github.io/comprehensive-rust/"&gt;Comprehensive Rust&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://google.github.io/comprehensive-rust/concurrency/async-pitfalls/async-traits.html"&gt;https://google.github.io/comprehensive-rust/concurrency/async-pitfalls/async-traits.html&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="43-异步-trait"&gt;4.3 异步 Trait&lt;/h1&gt;
&lt;p&gt;Trait 中的异步方法在 1.75 版本中稳定。这需要支持在 trait 中使用返回位置的 &lt;code&gt;impl Trait&lt;/code&gt;，因为 &lt;code&gt;async fn&lt;/code&gt; 的脱糖包含 &lt;code&gt;-&amp;gt; impl Future&amp;lt;Output = ...&amp;gt;&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;不过，即便有原生支持，围绕 &lt;code&gt;async fn&lt;/code&gt; 仍有特定陷阱：&lt;/p&gt;</description></item><item><title>4.4 取消</title><link>https://before80.github.io/prgms/Rust/comprehensiveRust/concurrency-afternoon/async-pitfalls/04-cancellation/</link><pubDate>Tue, 11 Aug 2026 11:30:00 +0800</pubDate><guid>https://before80.github.io/prgms/Rust/comprehensiveRust/concurrency-afternoon/async-pitfalls/04-cancellation/</guid><description>&lt;blockquote&gt;
&lt;p&gt;译文 · 基于 &lt;a href="https://google.github.io/comprehensive-rust/"&gt;Comprehensive Rust&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://google.github.io/comprehensive-rust/concurrency/async-pitfalls/cancellation.html"&gt;https://google.github.io/comprehensive-rust/concurrency/async-pitfalls/cancellation.html&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="44-取消"&gt;4.4 取消&lt;/h1&gt;
&lt;p&gt;丢弃 future 意味着它再也不能被轮询。这称为&lt;em&gt;取消&lt;/em&gt;（cancellation），可以发生在任意 &lt;code&gt;await&lt;/code&gt; 点。需要小心确保即使 future 被取消，系统仍能正确工作。例如，不应死锁或丢失数据。&lt;/p&gt;</description></item></channel></rss>