V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
pluvet
V2EX  ›  分享创造

50 行代码写一个迷你无栈协程框架

  •  
  •   pluvet ·
    pluveto · 47 天前 · 1675 次点击
    这是一个创建于 47 天前的主题,其中的信息可能已经有所发展或是发生改变。
    玩具项目,不过真的很好玩!

    ```c
    int prime_factor_co(Co *co, void *data)
    {
    PrimeFactorData *pfData = (PrimeFactorData *)data;
    CO_BEGIN(co);

    pfData->current = 2;
    while (pfData->number > 1)
    {
    while (pfData->number % pfData->current == 0)
    {
    pfData->number /= pfData->current;
    pfData->factor = pfData->current;
    CO_YIELD(co, pfData->factor);
    }
    pfData->current++;
    CO_YIELD(co, 0); // Yield to indicate progress
    }

    CO_END(co);
    return 0;
    }
    ```

    https://zhuanlan.zhihu.com/p/710329144
    https://github.com/pluveto/minico
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2376 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 02:13 · PVG 10:13 · LAX 19:13 · JFK 22:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.