
Writing a fiber coroutine in C/C3
I love Go language because of it's simplicity AND the goroutine . I always thinking of having similar thing in C or C3 language. D language provides a very lightweight simple-minded coroutine, in the name of Fiber, very clean API. Recently I also get interested in C3 language. A modern successor of C language, cleaner, safer, stronger. So I set out to implement Fiber for C3 language. There are 4 different way of implementing Fiber coroutine. (1) Calling assembly code for context switching, (2) Using ucontext library on POSIX systems, (3) Using sigsetjmp/siglongjmp on POSIX, (4) Using native Fiber on windows. Fiber coroutine using Assembly Calling assembly code is extremely lightweight, but it is not very easy to maintain assembly codes for all architectures. For my case, I decided to cover only X86_64 and AARCH64, because they are most frequent platforms. Another issue with C3/inline assembly is that C3's assembly coverage is limited and it's not easy to express required inline assembl
Continue reading on Dev.to
Opens in a new tab




