Skip to content

Commit bc123c9

Browse files
authored
Update README.md (#8)
1 parent 2cc1805 commit bc123c9

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

README.md

+22-3
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,29 @@ despite they are keeping switch in and switch out.
123123
124124
```c++
125125
task<Tp> foo() {
126-
// By calling `bar()` a new coroutine is created. co_await it will suspend the current coroutine until the new coroutine returns.
127-
auto v = co_await bar(); // suspend before the co_await expression returns. When it is resumed, `v` will have the returned value from `bar`.
126+
// By calling `bar()` a new coroutine is created.
127+
// co_await it will suspend the current coroutine until the new coroutine returns.
128+
auto v = co_await bar(); // Suspend before the co_await expression returns.
129+
// When it is resumed, `v` will have the returned value from `bar`.
128130
// continue running
129-
co_return ...; // Finish this task. If this coroutine is also invoked by another coroutine, then the completion of `foo` will also lead another resumption.
131+
co_return ...; // Finish this task.
132+
// If this coroutine is also invoked by another coroutine,
133+
// then the completion of `foo` will also lead another resumption.
130134
}
131135
```
132136

137+
A `task` has two different types: it is either `deferred` or `async`. This is also very similar to the `std::launch`:
138+
a deferred task is a lazy-evaulation function, it won't run untill we try to get its result. On the other hand, an async task is a task that can be executed by a scheduler in the background.
139+
140+
`static_thread_pool` is our coroutine scheduler. Just as its name describes, it's a simple thread pool that not much different than other thread pool implementations.
141+
A `static_thread_pool` object is always associated with a time manager. The time manager manages the timer tasks (e.g., `this_scheduler::sleep_for`).
142+
It is implemented by a priority queue which always returns the task with the smallest timestamp.
143+
144+
**Awaiter** specifies the behaviour of how the scheduler switches coroutines. There are five different kind of awaiters in cosched. They are
145+
- `always_awaiter` Always suspends the current coroutine and puts it to the end of the scheduler's task queue.
146+
- `async_awaiter` is the most common awaiter. It appears when we invoke another coroutine (i.e., the callee) from the current coroutine (i.e., the caller).
147+
It won't suspend if the callee has finished (which means we can retrieve its result immediately), otherwise, it will suspend the caller and make it as the callee's "wait coroutine".
148+
Once a coroutine is finished, its `wait coroutine` will be back to the scheduler.
149+
- `parallel_awaiter` is similar to the `async_awaiter`, but it never suspend the current coroutine. If the scheduler has two or more worker threads, these two coroutines can run in parallel.
150+
- `final_awaiter` is the awaiter which returned by `final_suspend()` of the promise object. It retrieves the coroutine's "wait coroutine" and puts it back to the scheduler's task que.
151+
- `condition_awaiter` is a class template. Its behaviour can be customized. Our timer, latch, and mutex all utilize it.

0 commit comments

Comments
 (0)