Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adinosaur/Coro
用c语言setjmp和longjmp实现的一个最基本的协程
https://github.com/adinosaur/Coro
Last synced: 3 months ago
JSON representation
用c语言setjmp和longjmp实现的一个最基本的协程
- Host: GitHub
- URL: https://github.com/adinosaur/Coro
- Owner: adinosaur
- Created: 2016-09-19T02:24:20.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-20T11:43:56.000Z (about 8 years ago)
- Last Synced: 2024-07-16T13:05:07.348Z (4 months ago)
- Language: C++
- Homepage:
- Size: 2.93 KB
- Stars: 34
- Watchers: 5
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Coro
用c语言setjmp和longjmp实现的一个最基本的协程,详见[blog](http://www.cnblogs.com/adinosaur/p/5889014.html)。## Usage
使用包含头文件`#include"Coro.h"`,模块只有三个接口:1. coro_new创建一个协程。
2. coro_yield将控制返回给主(调度)协程。
3. coro_main运行主(调度协程)。
```
void co1(void* msg)
{
for (int i = 0; i != 5; ++i)
{
printf("%s\n", (char*)msg);
coro_yield();
}
}int main(int ac, char** av)
{
coro_new(co1, "hello");
coro_new(co1, "world");
coro_main();
return 0;
}
```