Live data from Hacker News

Coroutines in C (2000)

chiark.greenend.org.uk

51–60 of 61 posts

Re: Coroutines in C (2000)

#51

Earlier quoted context omitted.

I wonder if it would work from Rust. I was looking at something minimal like this.

I haven't used it at all, but doesn't Rust have experimental support for coroutines? https://github.com/rust-lang/rust/issues/43122

libdill and co implement stackful coroutines. Each coroutine has a native call stack which gets swapped out by a userspace scheduler. Rusts proposed coroutines and async functions are stackless. They are implemented as pure Compiler Transformations, and don’t allow to yield at arbitrary points.

Rust actually had stackless coroutines in the past (libgreen), but moved from it due to the overhead it brought for code that didn’t require it.

Re: Coroutines in C (2000)

#52
post #8

A really good library that we use is libco[0], it supports different architectures and mechanisms. We use it extensively on Fluent Bit[1] to manage async IO network operations (epoll + coroutines). - [0] https://byuu.org/library/libco/ - [1] https://fluentbit.io

Do you use https://github.com/Tencent/libco or https://byuu.org/library/libco/ ?

Re: Coroutines in C (2000)

#53

Earlier quoted context omitted.

I have, it's not pretty either: https://github.com/nraynaud/webgcode/blob/gh-pages/interpola...

i have done cps plumbing in C with poor mans closures for the entire interrupt path, and given its natural event-like nature, it really all comes out pretty nice.

If its possible would love to learn from it. Any chance of taking a look at it ?

Re: Coroutines in C (2000)

#54
post #47

Isn't this just an application of a protothread[1]? There are implementations that use the GCC goto and label pointer, which then avoid the need for a switch statement. [1] http://dunkels.com/adam/pt/

Answered here https://news.ycombinator.com/item?id=19109008 by VygmraMGVl

In lining the answer.

> Protothreads is a library implementation of this trick. In fact, the protothreads creator even references the linked site in their explanation of protothreads (very last paragraph)

Re: Coroutines in C (2000)

#55

Earlier quoted context omitted.

why?

Because it's not ergonomic. You don't need the browser to take up your entire screen, you just need it big enough so you can fit the content comfortably. Admittedly we would all lose this habit quicker if resizing windows wasn't such a finicky process in most OSs

I'm using this application: https://github.com/aarmea/WindowGroomer

sadly abandoned it seems, and not well-known, but is well-working in both win7 and win10. With a keyboard shortcut it's easy to resize any window and at the same time position them on the screen.

Also makes it easy to "save" windows that have slightly bad size or position so it's hard to position the mouse pointer in the resize corner.

On my wish list is that after bringing up the application, instead of using the mouse to select grid, I should be able to use eg arrow keys and shift to select them.

Re: Coroutines in C (2000)

#56
post #47

Isn't this just an application of a protothread[1]? There are implementations that use the GCC goto and label pointer, which then avoid the need for a switch statement. [1] http://dunkels.com/adam/pt/

Rather, the protothreads library is an application of this style of coroutine.

Re: Coroutines in C (2000)

#57
post #53

Earlier quoted context omitted.

i have done cps plumbing in C with poor mans closures for the entire interrupt path, and given its natural event-like nature, it really all comes out pretty nice.

If its possible would love to learn from it. Any chance of taking a look at it ?

the actual work was done under contract as in proprietary, but the closure library is the interesting part, is owned by me, and something i can send you.

accountname @gmail.com

if you're interested we can go over the interrupt path, its pretty straightforward at that point. by flipping the control flow around, the virtio virtqueue support for example becomes nice and self-contained. it provides an interrupt continuation to the interrupt layer, and each queue is initialized with a continuation to call on a dequeue. vector assignment is still a bit cross-cutting.

Re: Coroutines in C (2000)

#59

You could use thread_local variables these days for re-entrancy instead of the ctx->i idea.

Thread-local variables make it thread-safe, but still not re-entrant. That's ok, if you don't need more than one state per thread.

You’re right. Thanks.

Re: Coroutines in C (2000)

#60
post #53

Earlier quoted context omitted.

If its possible would love to learn from it. Any chance of taking a look at it ?

the actual work was done under contract as in proprietary, but the closure library is the interesting part, is owned by me, and something i can send you. accountname @gmail.com if you're interested we can go over the interrupt path, its pretty straightforward at that point. by flipping the control flow around, the virtio virtqueue support for example becomes nice and self-contained. it provides an interrupt continuat…

Thanks that is extremely generous of you.

I would still encourage that you put it up somewhere with a license of your choice. Many would get an opportunity to learn a thing or two.

Post reply on HN