Get the latest tech news
A memory safe C framework, RAII, I/O, coroutine and other concurrency primitives
A memory safe focus C framework, RAII, I/O, coroutine and other concurrency primitives.
## Design The *intergration* pattern for all **libuv** functions taking *callback* is as [queue-work.c](https://github.com/zelang-dev/c-asio/tree/main/examples/queue-work.c) **example**: ```c #define USE_CORO #include "raii.h" #define FIB_UNTIL 25 long fib_(long t) { if (t == 0 || t == 1) return 1; else return fib_(t-1) + fib_(t-2); } void_t fib(params_t req) { int n = req->integer; if (random() % 2) sleepfor(1); else sleepfor(3); long fib = fib_(n); fprintf(stderr, "%dth fibonacci is %lu in thrd: #%d\033[0K\n", n, fib, coro_thrd_id()); return casting(fib); } void after_fib(int status, rid_t id) { fprintf(stderr, "Done calculating %dth fibonacci, result: %d\n", status, result_for(id).integer); } int main(int argc, char **argv) { rid_t data[FIB_UNTIL]; int i; waitgroup_t wg = waitgroup_ex(FIB_UNTIL); for (i = 0; i < FIB_UNTIL; i++) { data[i] = go(fib, 1, casting(i)); } waitresult_t wgr = waitfor(wg); if ($size(wgr) == FIB_UNTIL) for (i = 0; i < FIB_UNTIL; i++) { after_fib(i, data[i]); } return 0; } ``` Every system **thread** has a **run queue** assigned, a ~tempararay~ *FIFO queue*, it holds **coroutine** *tasks*. * * Possible reasons for failing to spawn would include (but not be limited to) the * file to execute not existing, not having permissions to use the setuid or setgid * specified, or not having enough memory to allocate for the new process. */ C_API void coro_await_exit(routine_t *co, void_t result, ptrdiff_t plain, bool is_plain); /* Should be used as part of `coro_await` initialization function to indicate an `error` condition, where the `preset` callback WILL NOT be called.
Or read this on Hacker News