Live data from Hacker News

Show HN: Libconcurrent – Coroutines in C

github.com

1–10 of 26 posts

Re: Show HN: Libconcurrent – Coroutines in C

#2
The links to other projects with similar goals at the bottom of the Readme is brilliant. It helps developers solve their problems irrespective of whether this particular solution works...and solving problems not stars and forks is the measure of utility for a library.

Re: Show HN: Libconcurrent – Coroutines in C

#3
Cool!

A co-TA and I ported the concurrency library in JOS, MIT's teaching operating system, to regular UNIX:

https://github.com/geofft/vireo

It uses the standard-ish library functions setcontext and getcontext to avoid an assembly dependency. ("POSIX.1-2008 removes the specification of getcontext(), citing portability issues, and recommending that applications be rewritten to use POSIX threads instead.")

Re: Show HN: Libconcurrent – Coroutines in C

#5
post #4

I got a silly question: Is this statement basically a do while/while(true) infinite loop? for (;;) { ... }

Yes. You're likely to run into this construct often in C.

Lots of people do it because stupid C compilers produce better code for `for(;;)` than they do for `while(1)` and stupid C compilers used to be very common.

It's also one less character spent: A rare win/win.

Re: Show HN: Libconcurrent – Coroutines in C

#7
post #5
post #4

I got a silly question: Is this statement basically a do while/while(true) infinite loop? for (;;) { ... }

Yes. You're likely to run into this construct often in C. Lots of people do it because stupid C compilers produce better code for `for(;;)` than they do for `while(1)` and stupid C compilers used to be very common. It's also one less character spent: A rare win/win.

Cool, thanks! I have yet to learn C other than from what I've learned from programming in C++.

I am really interested in learning some C however, especially after this post hit front page a few days ago:

https://matt.sh/howto-c

Re: Show HN: Libconcurrent – Coroutines in C

#9
post #2

The links to other projects with similar goals at the bottom of the Readme is brilliant. It helps developers solve their problems irrespective of whether this particular solution works...and solving problems not stars and forks is the measure of utility for a library.

It's missing this link, which I previously thought was "the" co-routine de-facto standard for C before seeing all those other links: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html

There's a link to the .h file near the bottom of the page.

That technique is what's used in protothreads and Contiki OS.

Re: Show HN: Libconcurrent – Coroutines in C

#10
post #3

Cool! A co-TA and I ported the concurrency library in JOS, MIT's teaching operating system, to regular UNIX: https://github.com/geofft/vireo It uses the standard-ish library functions setcontext and getcontext to avoid an assembly dependency. ("POSIX.1-2008 removes the specification of getcontext(), citing portability issues, and recommending that applications be rewritten to use POSIX threads instead.")

*context are unfortunately quite slow as they require a system call to update the signal mask. The sigaltstack trick popularized by Pth is probably still more portable and faster.

BTW makecontext and friend were made obsolete by posix for a technicality: makecontext signature isn't expressible any longer in a strictly conforming C99 applications, although in practice it will work with any C compiler.

Ironically this happened around the same time that coroutines started becoming popular again.

Post reply on HN