{"id":13730084,"url":"https://github.com/flipcoder/mx","last_synced_at":"2025-05-08T02:31:10.876Z","repository":{"id":141705552,"uuid":"145771161","full_name":"flipcoder/mx","owner":"flipcoder","description":"C++ coroutine await, yield, channels, i/o events (single header + link to boost)","archived":false,"fork":false,"pushed_at":"2019-01-06T00:51:55.000Z","size":17,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-14T20:39:16.165Z","etag":null,"topics":["await","concurrency","coroutines","cpp","cpp11","iomultiplexing","threads","yield"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flipcoder.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-22T22:51:57.000Z","updated_at":"2019-09-21T11:55:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"52fbab11-90cb-46d8-8f11-ad46a780d917","html_url":"https://github.com/flipcoder/mx","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/flipcoder%2Fmx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipcoder%2Fmx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipcoder%2Fmx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipcoder%2Fmx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flipcoder","download_url":"https://codeload.github.com/flipcoder/mx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252986716,"owners_count":21836212,"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":["await","concurrency","coroutines","cpp","cpp11","iomultiplexing","threads","yield"],"created_at":"2024-08-03T02:01:09.657Z","updated_at":"2025-05-08T02:31:10.864Z","avatar_url":"https://github.com/flipcoder.png","language":"C++","readme":"# mx\n\nC++11 coroutine await, yield, channels, i/o events (single header + link to boost).\n\nThis was originally part of my c++ util library [kit](https://github.com/flipcoder/kit), but I'm separating it.  I haven't\nmoved the net/socket stuff yet, but check out [kit's net.h sockets](https://github.com/flipcoder/kit/blob/master/kit/net/net.h) to see how to use this in that context.\n\nIt's \"single header\" but requires you link to some boost libs.\n\n**This is a prototype.** There are still issues with stability and lack of features, maybe even thread safety. You've been warned!\nThis should serve as a proof-of-concept regardless.\n\nHere are the basics: there is a singleton i/o multiplexer (i.e. \"MX\") which is initialized on first usage.\nThe number of circuits is by default set to your core count, but wraps back around beyond that.\n\nYou give the \"circuit number\" you wish to operate on.  This index is a hint on how the separate the tasks across\ncores.  Because of the wraping of circuit indices, numbers that are closer together are more likely to be put on a different cores.\n\nYou can use local_shared_ptrs if you want, since each circuit has its own thread.\n\nIf you're familiar with Go, the mx's \"coro\" method (accessed by MX[0].coro\\\u003cvoid\\\u003e below) is similar to using \"go\".\n\n```c++\n// on circuit 0, launch coroutine, return future\u003cvoid\u003e\nauto fut = MX[0].coro\u003cvoid\u003e([]{\n    // do async stuff\n    auto foo = MX_AWAIT(bar);\n\n    // async sleep yield\n    MX_SLEEP(chrono::milliseconds(100));\n});\n\n// use fut here\n\n```\n\n```c++\n// on circuit 0, launch coroutine, using kit's sockets, which is also a prototype implementation\nMX[0].coro\u003cvoid\u003e([\u0026]{\n    for(;;)\n    {\n        auto client = make_local_shared\u003cTCPSocket\u003e(MX_AWAIT(server-\u003eaccept()));\n        \n        // coroutine per client\n        MX[0].coro\u003cvoid\u003e([\u0026, client]{\n            int client_id = client_ids++;\n            cout \u003c\u003c \"client \" \u003c\u003c client_id \u003c\u003c \" connected\" \u003c\u003c endl;\n            try{\n                for(;;)\n                    MX_AWAIT(client-\u003esend(MX_AWAIT(client-\u003erecv())));\n            }catch(const socket_exception\u0026 e){\n            }\n        });\n    }\n});\n\n```\n\nI don't have documentation of all features, check out mx.h if you're brave.\n\n## Future\n\nCurrently, you can await more than one future in a circuit, but this causes a polling situation that requires a stabizing timer\nto prevent wasting the CPU.  The next thing to add would be utilizing a shared method of polling (such as libuv)\nand responding to user futures through callbacks instead of being polled.\n\n## LICENSE\n\nOpen-source under MIT License.\n\nSee LICENSE file for details.\n\nCopyright (c) Grady O'Connell, 2013\n\n\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipcoder%2Fmx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflipcoder%2Fmx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipcoder%2Fmx/lists"}