https://github.com/supercip971/fibres
Coroutines/fibers implementation in C99
https://github.com/supercip971/fibres
c c99 coroutines fibers
Last synced: about 1 year ago
JSON representation
Coroutines/fibers implementation in C99
- Host: GitHub
- URL: https://github.com/supercip971/fibres
- Owner: Supercip971
- License: other
- Created: 2023-02-12T15:15:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-16T13:17:32.000Z (over 3 years ago)
- Last Synced: 2025-03-20T18:04:29.292Z (over 1 year ago)
- Topics: c, c99, coroutines, fibers
- Language: C
- Homepage:
- Size: 10.7 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
# Fibers (or coroutines) in C99 !
Just a sample project for a blog article I'm writing about fibers in C (for linux), that you can read here: [cyp.sh/blog/coroutines-in-c](https://cyp.sh/blog/coroutines-in-c) .
It's mainly inspired by an old code I wrote for [Brutal](https://github.com/brutal-org/brutal).
It's an experimentation and it should be used for learning purpose, there is some issues with
this code.
## Examples:
```c
#include "fibers.h"
void foo(void* args)
{
for(int i = 0; i < 10; i++)
{
printf("hello");
yield();
}
}
void bar(void* args)
{
for(int i = 0; i < 20; i++)
{
printf(" world! \n");
yield();
}
}
int main(int argc, char** argv)
{
FiberID a = fiber_launch(foo, NULL);
FiberID b = fiber_launch(bar, NULL);
fiber_join(a);
fiber_join(b);
return 0;
}
```