???Э??? C/C++ ???
???????????? ???????[ 2014/8/13 16:51:45 ] ??????????????? NET
????????
?????????????????Э?????????ú?????????????????????????????????????????????????Э?????????????????????????????????????鷳?????????????????????????á????????????????????Э???????л?????????????????????
???????м???????Э????????????? C/C++ ?????????????????????????????????Щ???????? C ????? setjmp ?? longjmp ???????????????? static local ???????????Э??????????????????д??????? static local ???????????????????????????????е??漼????????????? ?????????????????????????????????
???????????
?????? C/C++ ?????????????????????????????????????????漰????????????????? CPU ??????????????????????????? C/C++ ??????涼?????????壬????????????????????????????? C/C++ ????????????ò????????? API????????????????????????????????????????? POSIX ?? pthread ??????????Э?????????????Pthread??????????????????????????Э??????????????????????????????Э?????????????????
???????????????????????????????? pthread_create ?????????????????????????????????????????????????????????????? CPU ???????????????????????????????? C ????? setjmp ????Щ?????????????? buffer ???檔?????????????????????????????????????????????????????????????????????????????????? pthread_attr_setstack ?????????????????????????????????????????????????????????????????????????????????????? longjmp ???????
??????????????
?????????? RoutineInfo ????塣????????????д??????????????????汾??????? coroutine.cpp ????У??????????? coroutine_demonstration.cpp ????С?
typedef void * (*RoutineHandler)(void*);
struct RoutineInfo{
void * param;
RoutineHandler handler;
void * ret;
bool stopped;
jmp_buf buf;
void *stackbase;
size_t stacksize;
pthread_attr_t attr;
// size: the stack size
RoutineInfo(size_t size){
param = NULL;
handler = NULL;
ret = NULL;
stopped = false;
stackbase = malloc(size);
stacksize = size;
pthread_attr_init(&attr);
if(stacksize)
pthread_attr_setstack(&attr??stackbase??stacksize);
}
~RoutineInfo(){
pthread_attr_destroy(&attr);
free(stackbase);
}
};
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11