Home » Developing U++ » UppHub » Coroutines package for U++
Re: Coroutines package for U++ [message #59133 is a reply to message #59130] |
Mon, 07 November 2022 20:07   |
Oblivion
Messages: 1206 Registered: August 2007
|
Senior Contributor |
|
|
Hello koldo,
Quote:why does a programmer need to use coroutines?
Simple: To write non-blocking APIs or programs without spaghetti code: Recall the initial version of our very own SSH package. It was designed to be fully NB. This was achieved using a blend of an event queue, storing callbacks in a bivector (in a predefined order) and tracking their state. It did work, but the underlying code was very complex. (Fun fact: The same mechanism (but a stripped down version) is still used in NetProxy package.)
Now, the coroutines eliminates BOTH. You don't need to track the state of the internals of the NB object externally or worry about a state machine. Basically it is done for you by the compiler.
You write a local code block, and mark some points (usually where the code WOULDBLOCK) to suspend the coroutine and the compiler simply suspends it and returns the control back to its caller. The suspended coroutine can be resumed later from where it is left off.
This simplifites writing NB/async apps without using threads. Not to mention that you you don't need to worry about on how to terminate it. (CoRoutines are scope bound objects.)
Hello Peter:
Quote:I do not fully understand it yet and the purpose of it.
Well I don't think this debate (stackfull/stackless, i mean) will ever end --theoretically, at least. In practice, however, stackless coroutines are selected for C++20 (as in AFAIK C# and Python).
They can't be nested directly, yes.Some see this as a disadvantage, some don't. (I'm on the latter camp, since it forces simpler coroutines. (as no nesting is possible.)
As for the GDB: Yes it still can't handle coroutines properly..
A side note: I will add more complex examples to the package along with docs...
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Mon, 07 November 2022 20:27] Report message to a moderator
|
|
|
 |
|
Coroutines package for U++
By: Oblivion on Sat, 05 November 2022 12:19
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Sun, 06 November 2022 20:20
|
 |
|
Re: Coroutines package for U++
By: Klugier on Sun, 06 November 2022 20:44
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Sun, 06 November 2022 21:31
|
 |
|
Re: Coroutines package for U++
By: Lance on Mon, 07 November 2022 00:14
|
 |
|
Re: Coroutines package for U++
By: koldo on Mon, 07 November 2022 08:39
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Mon, 07 November 2022 20:07
|
 |
|
Re: Coroutines package for U++
By: peterh on Mon, 07 November 2022 20:30
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Mon, 07 November 2022 20:31
|
 |
|
Re: Coroutines package for U++
By: peterh on Tue, 08 November 2022 09:09
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Wed, 09 November 2022 16:22
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Wed, 09 November 2022 22:52
|
 |
|
Re: Coroutines package for U++
By: Lance on Wed, 09 November 2022 23:26
|
 |
|
Re: Coroutines package for U++
By: Lance on Sat, 12 November 2022 00:33
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Sat, 12 November 2022 07:22
|
 |
|
Re: Coroutines package for U++
By: Lance on Sun, 13 November 2022 05:37
|
 |
|
Re: Coroutines package for U++
By: Lance on Mon, 14 November 2022 02:17
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Mon, 14 November 2022 05:56
|
 |
|
Re: Coroutines package for U++
By: Lance on Mon, 14 November 2022 15:08
|
 |
|
Re: Coroutines package for U++
By: peterh on Mon, 07 November 2022 18:38
|
 |
|
Re: Coroutines package for U++
By: zsolt on Mon, 12 December 2022 13:48
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Mon, 12 December 2022 17:42
|
 |
|
Re: Coroutines package for U++
By: zsolt on Mon, 12 December 2022 21:38
|
Goto Forum:
Current Time: Sat May 10 19:39:11 CEST 2025
Total time taken to generate the page: 0.02444 seconds
|