Skip to content

Commit

Permalink
Ch. 17: pull disconnected material out of 17.01
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskrycho committed May 10, 2024
1 parent d61b736 commit 4b6867e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
20 changes: 0 additions & 20 deletions src/ch17-01-tasks.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
## Futures and the Async Syntax

As we saw in the previous chapter, threads provide one approach to concurrency,
and they let us solve some of these issues. However, they also have some
tradeoffs. On many operating systems, they use a fair bit of memory for each
thread, and they come with some overhead for starting up and shutting down.
Threads are also only an option when your operating system and hardware support
them! While mainstream desktop and mobile operating systems have all had
threading for many years, many embedded operating systems, like those used on
some microcontrollers, do not.

The async model provides a different—and ultimately complementary—set of
tradeoffs. In

<!-- TODO: the following paragraph is not where it needs to be structurally. -->

In the async model, concurrent operations do not require their own threads.
Instead, they can run on *tasks*. A task is a bit like a thread, but instead of
being managed by the operating system, it is managed by a runtime.

<!-- TODO: connective tissue as it were. -->

Like other languages with async, Rust uses the `async` and `await`
keywords—though with some important differences, as we will see. Blocks and
functions can be marked `async`, and you can wait on the result of an `async`
Expand Down
23 changes: 23 additions & 0 deletions src/ch17-03-vs-threads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- TODO: find the right home for this (maybe nowhere!) -->

As we saw in the previous chapter, threads provide one approach to concurrency,
and they let us solve some of these issues. However, they also have some
tradeoffs. On many operating systems, they use a fair bit of memory for each
thread, and they come with some overhead for starting up and shutting down.
Threads are also only an option when your operating system and hardware support
them! While mainstream desktop and mobile operating systems have all had
threading for many years, many embedded operating systems, like those used on
some microcontrollers, do not.

The async model provides a different—and ultimately complementary—set of
tradeoffs. In the async model, concurrent operations do not require their own
threads. Instead, they can run on *tasks*. A task is a bit like a thread, but
instead of being managed by the operating system, it is managed by code that
lives at the level of libraries.

<!--
TODO: connective tissue as it were. Also, an open question on whether we want
to use “task” as the primary term here. Futures do not actually *require* a
task primitive to run (and there are runtimes which do *not* use tasks!) so it
might make more sense to find another common, appropriate term for it instead.
-->

0 comments on commit 4b6867e

Please sign in to comment.