Skip to Content
Async Rust ―高いパフォーマンスと安全性を両立するRustによる非同期処理
book

Async Rust ―高いパフォーマンスと安全性を両立するRustによる非同期処理

by Maxwell Flitton, Caroline Morton, 中田 秀基
July 2025
Intermediate to advanced
284 pages
4h 4m
Japanese
O'Reilly Japan, Inc.
Content preview from Async Rust ―高いパフォーマンスと安全性を両立するRustによる非同期処理

3章非同期キューの自作

これまでに、非同期構文の基本を説明し、高レベルな非同期の概念を用いて問題を解決した。しかし、タスクとフューチャの実態や、これらが非同期ランタイムで処理される過程について、完璧には理解できていないだろう。フューチャやタスクは、説明するのも理解するのも難しい。本章では、これまでにフューチャやタスクや非同期ランタイムでの処理について学んだことを定着させるために、最小限の外部ライブラリを用いて非同期キューを自作する。

この非同期ランタイムは、キューの数や、個々のキューを処理するスレッドの数を変更することができる。それぞれのキューが同じである必要はない。例えば、2つしか処理スレッドを持たない低優先度のキューと、5つの処理スレッドを持つ高優先度のキューを用意することもできる。フューチャを処理する際に、キューを選択することができる。さらに、タスクスティーリングを実装する。あるキューが空になった場合に、別のキューからタスクをスティールするのだ。最後に、非同期ランタイムを高い抽象度で利用できるようにマクロを自作する。

本章を読めば、非同期キューを自作できるようになり、フューチャやタスクが非同期ランタイムで処理される過程を完全に理解できるようになるだろう。また、非同期ランタイムをカスタマイズして、標準のランタイム環境をそのまま使うのでは解決できないような特殊な問題に対応できるようになるだろう。非同期キューを自作したいとは思わなくても、非同期ランタイムをより深く理解することで、高レベルな非同期クレートをうまく操作し効率的に問題を解決できるようになるはずだ。また、高レベルな非同期コードを書く場合にも存在する非同期コードのトレードオフを理解できるようになるだろう。

まず、タスクの起動の部分から非同期キューを構築していく。タスクの起動が非同期ランタイムのエントリポイントとなるからだ。この非同期ランタイムはカスタマイズ可能になっており、キューの数と、それぞれのキューを処理するスレッドの数を選択することができる。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Async Rust

Async Rust

Maxwell Flitton, Caroline Morton
Rust Web Programming

Rust Web Programming

Maxwell Flitton

Publisher Resources

ISBN: 9784814401185Publisher Website