Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #399992

Re: Co-routines (was Re: acquire + sleep + async)

From Michael S <already5chosen@yahoo.com>
Newsgroups comp.lang.c
Subject Re: Co-routines (was Re: acquire + sleep + async)
Date 2026-06-12 18:42 +0300
Organization A noiseless patient Spider
Message-ID <20260612184202.0000712b@yahoo.com> (permalink)
References (5 earlier) <110dpf8$17r3s$3@dont-email.me> <110ep17$1naub$8@dont-email.me> <110gnqf$24301$1@dont-email.me> <110gpt7$250f6$2@raubtier-asyl.eternal-september.org> <110gsbb$24ih1$5@dont-email.me>

Show all headers | View raw


On Fri, 12 Jun 2026 13:59:38 +0200
David Brown <david.brown@hesbynett.no> wrote:

> On 12/06/2026 13:18, Bonita Montero wrote:
> > Am 12.06.2026 um 12:42 schrieb David Brown:
> >   
> >> More sophisticated solutions involve longjmp and setjmp, which are 
> >> more flexible and do more automatically, but are quite a lot more 
> >> costly in runtime speed (but still much lighter than OS threads).  
> >> These libraries may be stackless or stackfull, with limited
> >> portability.  
> > 
> > With setjmp() and longjmp() you can jump out of a function,
> > but not back inside.  
> 
> Of course you can jump back - longjmp() jumps to where you had 
> previously called setjmp(), and you have a new setjmp() just before
> the longjmp() so that you can jump back.
> 
> >   
> >> C++20 gained stackless co-routines in the language, with keywords
> >> and standard library functions.  Not all tools implement them, and
> >> while they can automate some parts of using co-routines, they also
> >> involve a lot of boiler-plate code and type mess, making them much
> >> uglier and more error prone than in languages with clearer support
> >> for co- routines (like Python or Go).  
> > 
> > The boilerplate code is < 50 lines; so not much.
> >   
> 
> The source boilerplate code overhead for Protothreads is about a
> tenth of that.  The overhead for other C coroutine libraries (or
> coroutines in languages with real support) is basically nothing.
> 

Big part of inconvenience of C++ co-routines is because of need to
support constructors, destructors, including virtual ones and, worst
of all, exceptions.
C has none of those, so potentially similar stackless co-routines could
have been added more naturally. But there is one critical part of the
puzzle lacking - C++ style co-routines depend on heap. In C++ heap is a
part of the core language, so there are no difficulties. In C, on the
other hand, heap management belongs to Standard Library rather than to
core language. In free-standing C implementation heap management can
be completely absent. Last year I tried (not vary hard) to find
solution to that problem, but language design is not really my cup of
tee, so I was unable to invent anything satisfactory.

At the end I came to conclusion, that for sort of jobs (in memory
constrained embedded environment) where I would not mind having
stackless co-routines, they are not necessarily the best
technical solution.
It's quite possible that normal co-routines, a.k.a. fibers, are better
solution. And fibers don't have to be part of core language or even of
Standard Library. However, fibers have one problem for which I would
prefer language support - sometimes, when running in slim fiber, I want
to call a "heavy" function, like sprintf or such, sort of function that
in worst case needs a lot of stack space. Today in such case I have to
provide a space for such function on stack of each and any fiber that
can potentially use it. If I have dozens of fibers, that would be quite
a lot wasted memory - instead of ~200 byte per fiber, or may be even
less, I'd have to allocate few KB. That's where enhancement in core
language code be handy - I want an ability to call a function not at
current stack, but on some sort of common stack, shared by all fibers
of the program. Or in case of multithreaded program, shared by all
fibers of particular thread. Of course, in theory that sort of
trampoline call/return could be implemented as a 3rd party library
function as well, but somehow I fill that it belongs to language, at
least as much as setjmp/lonjmp belongs to it, but preferably even in
more integrated manner,

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

acquire + sleep + async fir <profesor.fir@gmail.com> - 2026-06-10 13:53 +0200
  Re: acquire + sleep + async fir <profesor.fir@gmail.com> - 2026-06-10 16:03 +0200
  Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-11 04:40 +0000
    Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-11 07:20 +0200
      Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-11 06:28 +0000
        Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-11 09:21 +0200
          Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-11 07:45 +0000
            Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-11 15:56 -0700
          Re: acquire + sleep + async David Brown <david.brown@hesbynett.no> - 2026-06-11 09:52 +0200
            Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-11 10:28 +0200
              Re: acquire + sleep + async fir <profesor.fir@gmail.com> - 2026-06-11 10:44 +0200
                Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-11 11:36 +0200
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-12 01:32 +0000
                Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-12 06:16 +0200
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-11 21:19 -0700
                Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-12 13:15 +0200
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-22 12:15 -0700
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-12 23:52 +0000
                Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-13 05:05 +0200
                Re: acquire + sleep + async scott@slp53.sl.home (Scott Lurndal) - 2026-06-13 14:52 +0000
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-16 00:12 +0000
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-16 12:22 -0700
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-17 03:09 +0000
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-17 20:29 -0700
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-17 20:30 -0700
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-18 04:11 +0000
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-18 00:18 -0700
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-18 07:23 +0000
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-23 11:47 -0700
                Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-18 18:23 +0200
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-18 12:46 -0700
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-18 23:01 +0000
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-19 13:34 -0700
                Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-20 11:47 +0200
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-20 22:41 +0000
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-20 23:29 +0000
                Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-21 09:06 +0200
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-21 07:50 +0000
                Re: acquire + sleep + async David Brown <david.brown@hesbynett.no> - 2026-06-21 12:22 +0200
                Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-21 13:41 +0200
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-11 16:01 -0700
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-12 01:33 +0000
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-11 21:05 -0700
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-12 23:54 +0000
              Re: acquire + sleep + async David Brown <david.brown@hesbynett.no> - 2026-06-11 13:39 +0200
                Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-11 16:44 +0200
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-11 21:11 -0700
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-13 00:01 +0000
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-13 13:46 -0700
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-14 00:32 +0000
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-16 12:23 -0700
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-17 03:07 +0000
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-18 12:47 -0700
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-18 12:51 -0700
              Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-12 00:14 +0000
                Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-11 21:16 -0700
            Re: acquire + sleep + async fir <profesor.fir@gmail.com> - 2026-06-11 10:34 +0200
              Re: acquire + sleep + async Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-11 11:38 +0200
                Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-12 00:13 +0000
            Co-routines (was Re: acquire + sleep + async) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-06-11 18:50 +0200
              Re: Co-routines (was Re: acquire + sleep + async) David Brown <david.brown@hesbynett.no> - 2026-06-12 12:42 +0200
                Re: Co-routines (was Re: acquire + sleep + async) Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-12 13:18 +0200
                Re: Co-routines (was Re: acquire + sleep + async) David Brown <david.brown@hesbynett.no> - 2026-06-12 13:59 +0200
                Re: Co-routines (was Re: acquire + sleep + async) Michael S <already5chosen@yahoo.com> - 2026-06-12 18:42 +0300
                Re: Co-routines (was Re: acquire + sleep + async) David Brown <david.brown@hesbynett.no> - 2026-06-12 18:20 +0200
                Re: Co-routines (was Re: acquire + sleep + async) Bonita Montero <Bonita.Montero@gmail.com> - 2026-06-12 18:58 +0200
                Re: Continuations (was Re: Coroutines) Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-13 00:04 +0000
                Re: Co-routines (was Re: acquire + sleep + async) Bart <bc@freeuk.com> - 2026-06-12 14:51 +0100
                Re: Co-routines (was Re: acquire + sleep + async) David Brown <david.brown@hesbynett.no> - 2026-06-12 16:04 +0200
                Re: Co-routines (was Re: acquire + sleep + async) Bart <bc@freeuk.com> - 2026-06-12 16:16 +0100
                Re: Co-routines (was Re: acquire + sleep + async) David Brown <david.brown@hesbynett.no> - 2026-06-12 17:31 +0200
                Re: Co-routines (was Re: acquire + sleep + async) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-06-12 13:48 -0700
                Re: Co-routines (was Re: acquire + sleep + async) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-13 14:13 -0700
                Re: Co-routines (was Re: acquire + sleep + async) fir <profesor.fir@gmail.com> - 2026-06-12 16:25 +0200
                Re: Co-routines (was Re: acquire + sleep + async) fir <profesor.fir@gmail.com> - 2026-06-12 16:28 +0200
                Re: Co-routines (was Re: acquire + sleep + async) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-06-12 19:13 +0200
                Re: Co-routines (was Re: acquire + sleep + async) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-06-12 13:45 -0700
                Re: Co-routines (was Re: acquire + sleep + async) Bart <bc@freeuk.com> - 2026-06-13 01:03 +0100
                Re: Co-routines (was Re: acquire + sleep + async) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-06-12 17:50 -0700
                Re: Co-routines (was Re: acquire + sleep + async) Bart <bc@freeuk.com> - 2026-06-13 11:03 +0100
                Re: Co-routines (was Re: acquire + sleep + async) tTh <tth@none.invalid> - 2026-06-13 12:14 +0200
                Re: Co-routines (was Re: acquire + sleep + async) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-06-13 14:35 +0200
                Re: Co-routines (was Re: acquire + sleep + async) Bart <bc@freeuk.com> - 2026-06-13 14:38 +0100
                Re: Co-routines (was Re: acquire + sleep + async) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-06-13 16:46 -0700
                Re: Co-routines (was Re: acquire + sleep + async) Bart <bc@freeuk.com> - 2026-06-14 01:25 +0100
                Re: Co-routines (was Re: acquire + sleep + async) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-06-13 18:26 -0700
                Re: Co-routines (was Re: acquire + sleep + async) Bart <bc@freeuk.com> - 2026-06-14 12:28 +0100
                Re: Co-routines (was Re: acquire + sleep + async) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-06-14 15:01 -0700
                Re: Co-routines (was Re: acquire + sleep + async) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-06-22 19:46 +0200
                Re: Co-routines (was Re: acquire + sleep + async) scott@slp53.sl.home (Scott Lurndal) - 2026-06-22 21:24 +0000
                Re: Co-routines (was Re: acquire + sleep + async) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-06-23 01:16 +0200
                Re: Co-routines (was Re: acquire + sleep + async) Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-08-14 12:45 -0700
                Re: Co-routines (was Re: acquire + sleep + async) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-06-13 03:48 -0700
                Re: Co-routines (was Re: acquire + sleep + async) Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-06-21 18:22 -0700
                Re: Co-routines (was Re: acquire + sleep + async) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-06-12 18:14 +0200
    Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-11 14:18 -0700
      Re: acquire + sleep + async Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-12 00:12 +0000
        Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-11 21:06 -0700
          Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-16 12:25 -0700
            Re: acquire + sleep + async "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-17 12:11 -0700

csiph-web