Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is block_on an executor? #219

Open
notgull opened this issue Jun 4, 2024 · 6 comments
Open

Is block_on an executor? #219

notgull opened this issue Jun 4, 2024 · 6 comments

Comments

@notgull
Copy link

notgull commented Jun 4, 2024

In general, but also in this book, I've heard the word "executor" refer to what I believe are two different concepts:

  • A queue of tasks scheduled to be ran across a set of threads (I would argue this is an executor, and smol::Executor is a good example of this).
  • A system that runs one single task to completion. For example, smol::future::block_on.

I think these are two different concepts, but they're often both referred to as "executors". Executor is not able to poll a future to completion on its own; it requires a top-level block_on for that. On the other hand, block_on on its own can only poll one future to completion.

Internally I've referred to the latter case (block_on) as a "reactor"; however it seems this is incorrect. async_io::block_on is fairly certainly a reactor, since it handles I/O events and timers.

However, futures_lite::block_on is in a gray area here. It handles no I/O events, it just polls the future to completion. I would argue that this is a reactor in the same way that () is a type.

I'm wondering if the book can be updated to clarify the differences here.

@notgull
Copy link
Author

notgull commented Jun 4, 2024

cc smol-rs/async-task#77

@lolbinarycat
Copy link

lolbinarycat commented Jun 4, 2024

another important thing to consider is crates that provide futures for io, and launch a background thread in order to Wake those futures, notifying the executor when they can make progress, but do not provide any way of polling those futures.

in short, there are two parts:

  1. the executor, which calls Future::poll (possibly just in a loop, possibly with some scheduling logic)
  2. some sort of background thread that calls Waker::wake when a future can make progress (is this the reactor?)

note the 2 is actually optional, a simple future can just call Waker::wake() immediatly before returning Poll::Pending. the second thing defiantly needs a name though.

@lolbinarycat
Copy link

my interpretation (mostly informed by reading std::thread) is as follows:

  1. if it calls Future::poll, it's an executor
  2. if it calls Waker::wake after a future returns Pending, it's a reactor
  3. if it does both, then it is both

although the docs are a bit unclear, so i'm unsure if this is the intended interpretation. adding a Glossary section to the async book would probably help.

@lolbinarycat
Copy link

@lbernick you wrote the relevant paragraph, mind weighing in on this?

@lbernick
Copy link
Contributor

Sorry @lolbinarycat, I haven't worked on async rust in a few years so I don't think I'm the best person to weigh in here.

@lolbinarycat
Copy link

i'm just asking what you meant when you wrote that words

i'm really not sure who else could weigh in on this.. i guess it becomes an issue of prescriptivism vs descriptivism.. i guess a survey of how the words are used could help, but that's a lot of work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants