upvote
I do think they’re fundamentally different, for two reasons:

1. The decision of when to switch routines is more consequential than the cost of stack or context switching. Letting the OS decide results in behavior that is consistently fair for all programs, caveat scheduler bugs. Letting user code decide results in behavior that is only as fair as a given program. Writing code in the latter environment entails wrestling with the reality that it may not run to completion unless other code in the environment lets it. That applies in async programming to a much wider range of situations than kill signals/aborts, which are the only even slightly analogous things in threaded programming.

2. Async is a subset of threaded programming (it has a hardware stack, and can call typical context-switchful code if it wants to block).

reply
You are describing preemption and time sharing with cooperative task switching. That's more or less orthogonal to async Vs not async.
reply
Is it? Almost all "async" systems use it to model cooperative task switching. I'm not aware of any runtimes that have the distinction of async vs. blocking work that don't do cooperative concurrency (which makes sense; cooperative concurrency is a good fit for code that is mostly IO completions hooked up to an efficient IO multiplexer).

On the other side, it's similar: blocking + preemptive multitasking (or no multitasking) are nearly always paired. Unless you wanna split hairs and say e.g. "because Golang and BEAM sometimes use singleton IO multiplexers under the hood, that makes them 'async'", which is not a useful or typically-understood description of the term. This is true in multi-process, multi-thread, and (I'd argue) many multi-actor systems as well.

I think the useful distinction around async-or-not is whether the language semantics distinguish yield/resume points or not. Like, I don't have to care if syscalls/time slices/whatever are the preemption points, but if I'm writing async code, the async boundaries are very important because they're potentially task switching boundaries.

Or are we using incompatible definitions of these terms?

reply
POSIX RT FIFO scheduling is effectively cooperative for threads of same priority pinned to the same CPU. On the other hand fo c++ coroutines running, for example on an asio scheduler served by a thread pool can't be considered cooperatively scheduled.
reply
Async also allows the stack to fork. Because it uses a linked list of stack frames instead of putting them all in sequential memory, it's relatively easy for a frame to hold links to more than one next frame and wait for all of them at once.

You also have the Golang model, where they use threads but they took care to make the threads very lightweight.

reply
> I look at it differntly. There is no fundamental difference between async paradigm and threads. The only difference is where the call stack is.

Exactly. Even "super fast stack allocation" Vs explicit stack frame is not such a defining characteristic. There are languages that look sequential but where each "stack[1]" frame is dynamically allocated and you can get async behaviour for "free". But the allocator is a stack and you get performance comparable to a more classical language.

At the end of the day, the main difference between the two paradigms is whether continuations are visible at the surface syntax level or not: they painfully are when writing CPS code by hand, they are partially hidden in languages with explicit async syntax and completely hidden in languages that look sequential.

[1] in quotes because function invocation does not need to respect a strict LIFO stack discipline.

reply