How do you implement Coroutines in C++

后端 未结 18 920
刺人心
刺人心 2020-12-02 04:17

I doubt it can be done portably, but are there any solutions out there? I think it could be done by creating an alternate stack and reseting SP,BP, and IP on function entry

18条回答
  •  醉梦人生
    2020-12-02 05:01

    I dont think there are many full-blown, clean implementations in C++. One try that I like is Adam Dunkels' protothread library.

    See also Protothreads: simplifying event-driven programming of memory-constrained embedded systems in the ACM Digital Library and discussion in Wikipedia topic Protothread,

提交回复
热议问题