Lightweight, portable C++ fibers, MIT license
Asked Answered
F

6

10

I would like to get ahold of a lightweight, portable fiber lib with MIT license (or looser). Boost.Coroutine does not qualify (not lightweight), neither do Portable Coroutine Library nor Kent C++CSP (both GPL).

Edit: could you help me find one? :)

Falsify answered 17/8, 2009 at 0:12 Comment(1)
Heh, seems like I found an unexploited area for All Them Altruists out there. :)Footpath
V
2

If Boost seems to heavy, helpful people have extracted the relevant parts of Boost (fcontext) as a standalone library, e.g. deboost.context.

Virgievirgil answered 17/6, 2020 at 16:31 Comment(0)
E
9
  1. Libtask: MIT License
  2. Libconcurrency: LGPL (a little tighter than MIT, but it's a functional library!)

Both are written for C.

Euphrosyne answered 24/8, 2009 at 10:46 Comment(2)
Looks like setcontext() / setmcontext() might be some work on certain platforms, but other than that looks readily portable.Footpath
There's no setcontext under cygwin.Valine
K
5

I actually blogged about this in the past. Have a look! I hope it answers your questions. In it, I cover a number of libraries, and I was particularly interested in ones that were useful for systems programming (asynchronous IO).

Conspicuously absent from that coverage is Boost.Coroutine, which I'll discuss here. Boost.Coroutine may be considered "heavyweight" conceptually (in terms of its family of types), but the implementation is quite efficient. The real problem is that Boost.Coroutine is incomplete, and (last I checked) far from complete. I had spent some time trying to work with the author through its non-starter issues, as I was really looking forward to using it in conjunction with Boost.Asio (this was one of Boost.Coroutine's primary objectives), but the author has not had the time to take his work to the Boost formal review stage.

Karlis answered 7/11, 2009 at 9:52 Comment(1)
I think your link has a bug. Try yz.mit.edu/wp/cooperative-threads-for-ccValine
M
3

list of implementations for C

for ultra lightweight "threads" take a look at Protothreads at the bottom of the wikipedia article.

Mikkel answered 18/8, 2009 at 8:27 Comment(2)
I eventually found sics.se/~adam/pt/download.html, which looks promising.Footpath
Prooved to be a switch/case wrapper with implicit state. Not what I was looking for, but still somewhat interesting.Footpath
A
2

Now you have two better options with Boost license:

Adze answered 17/1, 2017 at 14:21 Comment(0)
N
2

There is a blazing fast and lightweight C asymmetric coroutine library - libaco.

It is really small, very fast and extremely memory efficient:

Along with the implementation of a production-ready C coroutine library, here is a detailed documentation about how to implement a fastest and correct coroutine library and also with a strict mathematical proof;

It has no more than 700 LOC but has the full function you may want from a coroutine library;

The benchmark part shows that one time of the context switching between coroutines only takes about 10 ns (for the case of standalone stack) on the AWS c5d.large machine;

User could choose to create a new coroutine with a standalone stack or with a share stack (could be shared with others);

It is extremely memory efficient: 10,000,000 amount of co simultaneously to run only cost 2.8 GB physical memory (run with tcmalloc, each co has a 120B copy-stack size configuration).

It also has a very detailed documentation.

PS:

It is under the Apache License, Version 2.0.

Norvall answered 3/7, 2018 at 14:22 Comment(0)
V
2

If Boost seems to heavy, helpful people have extracted the relevant parts of Boost (fcontext) as a standalone library, e.g. deboost.context.

Virgievirgil answered 17/6, 2020 at 16:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.