Skip to content

Commit 54ea01c

Browse files
committed
update blocking section for accuracy
1 parent 275f0cb commit 54ea01c

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

tutorials/async.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,15 @@ While async is a great and powerful tool, in C++ it's unfortunately easy to misu
175175

176176
### Blocking
177177

178-
Blocking a thread of the async runtime is one of the worst things you can do, as it prevents all other tasks from running. Take this code for example:
178+
Blocking a thread of the async runtime is one of the **worst** things you can do, as it prevents all other tasks from running. Take this code for example:
179179

180180
```cpp
181181
async::spawn([] -> arc::Future {
182182
std::this_thread::sleep_for(std::chrono::seconds{1});
183183
});
184184
```
185185
186-
If you run this, you will likely get angry messages like this in your console:
187-
```
188-
[WARN] [Worker 1] task Task @ 0x7c4bc6fe0790 took 1.002s to yield
189-
```
190-
191-
This is because an async runtime has a fixed number of threads, which drive all tasks together. When you invoke an operation that waits *asynchronously*, for example `arc::sleep`, you tell the runtime "Hey, you can run other tasks for now, wake me up when I need to run", and it simply suspends your task. When you invoke a *blocking* operation, you bypass the runtime, steal its thread and don't give other tasks an opportunity to run.
186+
This is quite bad, since an async runtime has a fixed number of threads, which drive all tasks together. When you invoke an operation that waits *asynchronously*, for example `arc::sleep`, you tell the runtime "Hey, you can run other tasks for now, wake me up when I need to run", and it simply *suspends* your task. When you invoke a **blocking** operation, you bypass the runtime, steal its thread and don't give other tasks an opportunity to run.
192187
193188
Almost every blocking operation has a non-blocking counterpart in Arc:
194189
* Sleep -> `arc::sleep`

0 commit comments

Comments
 (0)