V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
pluvet

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

  •  
  •   pluvet ·
    pluveto · Jul 22, 2024 · 2126 views
    This topic created in 650 days ago, the information mentioned may be changed or developed.
    玩具项目,不过真的很好玩!

    ```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
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   829 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:19 · PVG 04:19 · LAX 13:19 · JFK 16:19
    ♥ Do have faith in what you're doing.