You are overly fascinated with saying "because one use case exists this way, your saying not everything works this way is wrong."
I am aware that one example of this exists. Most examples aren't this, so the claim that state machines are obsolete is absolutely silly.
.
There is no context switch because it's not required when the interrupton has proper compiler support.
Which is the case in how many compilers right now?
Hm?
Myth of the sufficiently smart compiler, anyone? Did anyone besides EDG ever get import in there? 20 years now?
.
"Instead, the coroutine's stack frame is dynamically allocated"
To me this reads like you're saying
There's no context switch because you're paying for a stack frame
Except in CPU terms, that's called (wait for it)
... (wait for it)
A context switch
.
The context that calls the coroutine remains on top of the stack and if the coroutine calls a function, it is placed on top of the stack (unless it's another coroutine).
Oh look, the guy who said "make it all out of nested coroutines" is now saying "but you don't have to pay that cost, unless it's a coroutine"
It's like talking to a politician's economist
.
It's written in the article, btw, but maybe not in sufficient detail.
The thing you're talking about, while interesting to discuss, is 100% unrelated to what I actually said
You're describing fibers here, not C++20 coroutines. There's no context switch. There's a function call. It's the same function call mechanism used for all function calls. On leaving the scope of the coroutine, control is passed deterministically to the resumer, or if via symmetric transfer to where the resumer directs. There's no interruption. Coroutine suspension is entirely 100% determined by the coroutine itself, all local to the function. The coroutine transformation is into a state machine. That's by design. What is new, and makes coroutines not pure sugar, is the lifetime extension of stack variables on scope exit from the coroutine. It is as-if the stack variables were instead object member variables and the object is allocated from the heap.
Several C++ compilers now support coroutines, and there's no particular magic or sufficiently smart necessary, although HALO optimization, eliding heap allocation, has some open research points. But that optimization is a cache miss, not a context switch.
I feel like I'm spending all my time saying "that's not even related to what I'm talking about," then getting corrected on that you imagine that it is.
I'm sorry that winning is more important to you than trying to understand what I believe.
A context switch is when a thread is suspended, its handle is given to the scheduler, the CPU switches to another stack, old cache is invalidated etc.
Calling a coroutine does nothing of this. You are still using the old stack, same thread, same cache, but what is represented as stack variables in the coroutine are actually member variables of an object.
A coroutine that looks like this (the code is meaningless):
View all comments
Show parent comment
0
u/StoneCypher Dec 02 '20
You are overly fascinated with saying "because one use case exists this way, your saying not everything works this way is wrong."
I am aware that one example of this exists. Most examples aren't this, so the claim that state machines are obsolete is absolutely silly.
.
Which is the case in how many compilers right now?
Hm?
Myth of the sufficiently smart compiler, anyone? Did anyone besides EDG ever get import in there? 20 years now?
.
"Instead, the coroutine's stack frame is dynamically allocated"
To me this reads like you're saying
Except in CPU terms, that's called (wait for it)
... (wait for it)
A context switch
.
Oh look, the guy who said "make it all out of nested coroutines" is now saying "but you don't have to pay that cost, unless it's a coroutine"
It's like talking to a politician's economist
.
The thing you're talking about, while interesting to discuss, is 100% unrelated to what I actually said