logoalt Hacker News

torginus • today at 12:31 PM • 4 replies • view on HN

The headline advertises 'no threads', but in the article, it mentions all actor methods are non-blocking, and async. Not blocking what?

The whole purpose of async is to have a message pump thread, and allow concurrency by yielding the timeslice. It's also needed because many async runtimes interact with APIs that need to be called from a single main OS thread.

I would presume an OS designed to be all actors, all the way down would do away with the need for a message pump thread, and single threaded APIs. In this case, cross-actor calls might as well be sync, with required preemption handled on the OS level.

Having to pay the async overhead over 100% of cross-actor calls is very expensive.


Replies

Asmod4n • today at 12:56 PM

There are two schools of thought for this.

One is the poll model, you ask the OS when you can use something.

The other one is the completion model, where you ask the OS to do something on your behalf and ask it when it’s done.

In the former you are the mailbox yourself, in the latter the OS is the mailbox.

When you are the mailbox yourself threads are kind of needed. When the OS is the mailbox it can implement them however it wants to.

I’d guess this OS is doing Mailbox duty itself instead of letting userspace handle it.

zelphirkalt • today at 1:13 PM

> The headline advertises 'no threads', but in the article, it mentions all actor methods are non-blocking, and async. Not blocking what?

I think the very brief answer to that is: "Processes." as in the general concept of communicating processes. How those are actually implemented on another layer depends on the platform. You can also run an actor system on a machine, that can only do one thing at a time, using a single CPU core. The work the process does is not blocking, but the platform might not have the capability to do more than one thing at a time. But this is different from work being inherently sequential.

inkyoto • today at 1:03 PM

«Threads» imply «shared state» within the confines of the same process, hence the need for locking primitives, mutexes, and alike.

«Actors» imply «no shared state» – there is a message inbox and a message outbox, but the state is private to the actor.

Both can be asynchronous.

➕ show 1 reply
imtringued • today at 12:45 PM

Threads are an OS level concept introduced by a kernel, e.g. the Linux kernel. If you do not have an OS at all, you do not have threads (lets ignore hardware threading for the sake of the argument). You just have the core itself be occupied by the actor scheduler, but no thread scheduler.

Blocking is not a threading or even OS concept. Blocking is a CPU core and programming language concept derived from sequential processing. Blocking means that instructions behind the block are not being executed while the block is in progress.

In the actor model, sending a message must never prevent the execution of instructions that follow after sending the message. The continued execution of further instructions must be guaranteed until the actor has processed the message. Responses must be received through the actor's mailbox.

Since blocking as an absolute concept may not make much sense, because all sequential processes (e.g. execution of an instruction) are blocking temporarily, the author decided instead to define a time bound, so if mail box processing takes too long, simply because the algorithm is CPU intensive, the author considers it blocked as well and schedules the next actor.

Edit: I guess the confusion comes from the fact that Rust's async facility automatically converts the code into a state machine that is compatible with actor execution semantics, but technically violates the spirit of actors.

➕ show 1 reply