{"id":13420677,"url":"https://github.com/sharow/libconcurrent","last_synced_at":"2025-04-06T13:11:31.907Z","repository":{"id":46763475,"uuid":"14114807","full_name":"sharow/libconcurrent","owner":"sharow","description":":copyright: Concurrent Programming Library (Coroutine) for C11","archived":false,"fork":false,"pushed_at":"2021-09-28T00:48:37.000Z","size":107,"stargazers_count":357,"open_issues_count":0,"forks_count":38,"subscribers_count":24,"default_branch":"master","last_synced_at":"2024-07-31T22:56:11.345Z","etag":null,"topics":["concurrency","concurrent","context-switching","coroutine","coroutine-library"],"latest_commit_sha":null,"homepage":"","language":"Assembly","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sharow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-04T15:50:39.000Z","updated_at":"2024-07-27T19:49:12.000Z","dependencies_parsed_at":"2022-09-25T05:01:54.776Z","dependency_job_id":null,"html_url":"https://github.com/sharow/libconcurrent","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharow%2Flibconcurrent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharow%2Flibconcurrent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharow%2Flibconcurrent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharow%2Flibconcurrent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sharow","download_url":"https://codeload.github.com/sharow/libconcurrent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247485287,"owners_count":20946398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","concurrent","context-switching","coroutine","coroutine-library"],"created_at":"2024-07-30T22:01:38.874Z","updated_at":"2025-04-06T13:11:31.883Z","avatar_url":"https://github.com/sharow.png","language":"Assembly","readme":"libconcurrent\n=============\n[![zlib License](http://img.shields.io/badge/license-zlib-orange.svg?style=flat-square)](https://github.com/sharow/libconcurrent/blob/master/LICENSE)\n\n\ntiny asymmetric-coroutine library.\n\n## Description\n+ asymmetric-coroutine\n+ bidirectional communication by `yield_value`/`resume_value`\n+ native context switch\n+ C11\n\n## Supported Platforms\n|              | x86_64              | i686                     | ARM(v6/v7)               | AArch64            | (contributor)    |\n|--------------|---------------------|--------------------------|--------------------------|--------------------|------------------|\n| Linux        | :heavy_check_mark:  | :heavy_check_mark:       | :heavy_check_mark:       | :heavy_check_mark: |                  |\n| FreeBSD      | :heavy_check_mark:  | :heavy_check_mark:       | :question:               | :question:         |[@t6](https://github.com/t6)|\n| OSX          | :heavy_check_mark:  | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: |[@kpamnany](https://github.com/kpamnany) |\n| (contributor)|                     |                          |                          |[@mitghi](https://github.com/mitghi)| |\n\n## Code Example\n\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cstdint.h\u003e\n#include \u003cstdnoreturn.h\u003e\n\n#include \u003cconcurrent/concurrent.h\u003e\n#include \u003cconcurrent/shortname.h\u003e\n\n#define STACK_SIZE (1024 * 2)\n\n\nnoreturn void accumulator(struct concurrent_ctx *ctx)\n{\n    int *v = ctx_get_resume_value(ctx);\n    int total = *v;\n    for (;;) {\n        v = yield_value(ctx, \u0026total); // send total / receive next value\n        total += *v;\n    }\n}\n\nint main(void)\n{\n    struct concurrent_ctx *ctx;\n    uint8_t stack[STACK_SIZE];\n    uint8_t ctx_alloc[ctx_sizeof()];\n    concurrent_init();\n    ctx = (struct concurrent_ctx *)ctx_alloc;\n    ctx_construct(ctx, stack, STACK_SIZE, accumulator, NULL);\n    for (int i = 1; i \u003c= 10; i++) {\n        int *total = resume_value(ctx, \u0026i); // send value / receive total\n        printf(\"total = %d\\n\", *total);\n        \n    }\n    ctx_destruct(ctx);\n    concurrent_fin();\n    return EXIT_SUCCESS;\n}\n\n/*\n$ gcc -o sample sample.c -lconcurrent.a\n$ ./sample\ntotal = 1\ntotal = 3\ntotal = 6\ntotal = 10\ntotal = 15\ntotal = 21\ntotal = 28\ntotal = 36\ntotal = 45\ntotal = 55\n*/\n```\n\n## Requirements for build\n- for x86_64/i686: [nasm](http://www.nasm.us/)\n\n\n## Installation\n```\n$ git clone https://github.com/sharow/libconcurrent.git libconcurrent\n$ cd libconcurrent\n$ make\n$ sudo make install\n\n```\n\n#### for FreeBSD\nAvailable in ports collection as [devel/libconcurrent](http://portsmon.freebsd.org/portoverview.py?category=devel\u0026portname=libconcurrent)\n\n\n#### for OSX\n- install latest [nasm](http://www.nasm.us/) from [brew](http://brew.sh)\n\n```\n$ brew install nasm\n```\n\n## Tests\n```\n$ make test\n\n```\n\n## Benchmark\n\n[examples/many_context1.c](https://github.com/sharow/libconcurrent/blob/master/examples/many_context1.c):\n\n```\n-- output: (Xeon E3 2.5Ghz)\n3000000 context switch in 373.5 ms\none context switch in 125 ns\n8031333 resume/yield pair per second\n\n\n-- output: (RaspberryPi2 ARMv7 900MHz)\n3000000 context switch in 2861.8 ms\none context switch in 954 ns\n1048287 resume/yield pair per second\n```\n\n\n## VS. \n+ Portable Coroutine Library (PCL): http://xmailserver.org/libpcl.html\n+ libtask: https://code.google.com/p/libtask/\n+ libconcurrency: http://code.google.com/p/libconcurrency/\n+ libcoro: http://software.schmorp.de/pkg/libcoro.html\n+ libcoroutine: https://github.com/stevedekorte/coroutine\n+ coro: http://www.goron.de/~froese/coro/\n+ libfiber: http://www.rkeene.org/projects/info/wiki/22\n+ mill: https://github.com/sustrik/mill\n+ fcontext: https://github.com/reginaldl/fcontext\n+ libwire: https://github.com/baruch/libwire\n+ coroutine(A asymmetric coroutine library for C): https://github.com/cloudwu/coroutine\n+ coroutine(a asymmetric coroutine (lua like) with fixed-size stack): https://github.com/xphh/coroutine\n+ coroutine(coroutine library with pthread-like interface in pure C): https://github.com/Marcus366/coroutine\n+ coroutines(A lightweight coroutine library written in C and assembler): https://github.com/xya/coroutines\n+ micro: https://github.com/mikewei/micoro\n","funding_links":[],"categories":["TODO scan for Android support in followings","Concurrency and Parallelism","Assembly","并发性和并行性"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharow%2Flibconcurrent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsharow%2Flibconcurrent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharow%2Flibconcurrent/lists"}