以下是最简单的C语言协程代码:
#include <stdio.h>
#include <ucontext.h>
ucontext_t context1, context2;
void func1() {
while (1) {
puts("In func1");
swapcontext(&context1, &context2);
}
}
void func2() {
while (1) {
puts("In func2");
swapcontext(&context2, &context1);
}
}
int main()