|
1 | 1 | ## Futures and the Async Syntax
|
2 | 2 |
|
3 |
| -As we saw in the previous chapter, threads provide one approach to concurrency, |
4 |
| -and they let us solve some of these issues. However, they also have some |
5 |
| -tradeoffs. On many operating systems, they use a fair bit of memory for each |
6 |
| -thread, and they come with some overhead for starting up and shutting down. |
7 |
| -Threads are also only an option when your operating system and hardware support |
8 |
| -them! While mainstream desktop and mobile operating systems have all had |
9 |
| -threading for many years, many embedded operating systems, like those used on |
10 |
| -some microcontrollers, do not. |
11 |
| - |
12 |
| -The async model provides a different—and ultimately complementary—set of |
13 |
| -tradeoffs. In |
14 |
| - |
15 |
| -<!-- TODO: the following paragraph is not where it needs to be structurally. --> |
16 |
| - |
17 |
| -In the async model, concurrent operations do not require their own threads. |
18 |
| -Instead, they can run on *tasks*. A task is a bit like a thread, but instead of |
19 |
| -being managed by the operating system, it is managed by a runtime. |
20 |
| - |
21 |
| -<!-- TODO: connective tissue as it were. --> |
| 3 | +<!-- |
| 4 | + TODO: connective tissue as it were. Also, an open question on whether we want |
| 5 | + to use “task” as the primary term here. Futures do not actually *require* a |
| 6 | + task primitive to run (and there are runtimes which do *not* use tasks!) so it |
| 7 | + might make more sense to find another common, appropriate term for it instead. |
| 8 | +--> |
22 | 9 |
|
23 | 10 | Like other languages with async, Rust uses the `async` and `await`
|
24 | 11 | keywords—though with some important differences, as we will see. Blocks and
|
|
0 commit comments