this image comes from Practical usage of setjmp and longjmp in C.
From my understanding, the coroutine
is two process looks like doing parallelly for human but actually doing a single process for machine.
But using setjmp
& longjmp
I feel very hard to read the code. If need to write the same one. For example process A & B, I will give serval States
to the processes to split them into different pieces(states),
do sequentially like:
Process A
switch (state)
case A1:
if (A1 is done)
do B1
break;
...
Process B
switch (state)
case B1:
if (B1 is done)
do A2
break;
...
I need a reason to support me use setjmp
& longjmp
& coroutine
in C/C++.
What's advantage?