{"id":15060121,"url":"https://github.com/owent/libcopp","last_synced_at":"2025-05-15T03:05:11.998Z","repository":{"id":12423371,"uuid":"15078266","full_name":"owent/libcopp","owner":"owent","description":"cross-platform coroutine library in c++","archived":false,"fork":false,"pushed_at":"2025-03-12T11:31:18.000Z","size":3091,"stargazers_count":846,"open_issues_count":0,"forks_count":106,"subscribers_count":41,"default_branch":"v2","last_synced_at":"2025-05-15T03:04:59.001Z","etag":null,"topics":["assembly","await","boost","c-plus-plus","coroutine","cpp","cross-platform","ha","high-performance","linux","lock-free","macos","performance","pool","stack","then","thread-safety","timer","window"],"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/owent.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","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":"2013-12-10T13:45:56.000Z","updated_at":"2025-05-09T07:00:30.000Z","dependencies_parsed_at":"2023-01-16T20:15:38.782Z","dependency_job_id":"3df060cb-a637-461b-9c9d-ff85555ab777","html_url":"https://github.com/owent/libcopp","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owent%2Flibcopp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owent%2Flibcopp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owent%2Flibcopp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owent%2Flibcopp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/owent","download_url":"https://codeload.github.com/owent/libcopp/tar.gz/refs/heads/v2","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264765,"owners_count":22041793,"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":["assembly","await","boost","c-plus-plus","coroutine","cpp","cross-platform","ha","high-performance","linux","lock-free","macos","performance","pool","stack","then","thread-safety","timer","window"],"created_at":"2024-09-24T22:53:13.162Z","updated_at":"2025-05-15T03:05:11.969Z","avatar_url":"https://github.com/owent.png","language":"C++","readme":"libcopp\n============\n\n.. _MIT LICENSE: https://github.com/owent/libcopp/blob/v2/LICENSE\n.. _`docs/libcopp.doxyfile.in`: https://github.com/owent/libcopp/blob/v2/docs/libcopp.doxyfile.in\n.. _`docs/sphinx`: https://github.com/owent/libcopp/blob/v2/docs/sphinx\n.. _cmake: https://cmake.org/\n.. _binutils: http://www.gnu.org/software/binutils/\n.. _llvm: http://llvm.org/\n.. _gtest: https://github.com/google/googletest\n.. _Boost.Test: (http://www.boost.org/doc/libs/release/libs/test\n.. _vcpkg: https://github.com/Microsoft/vcpkg\n\nCross-platform coroutine library in C++ .\n\n.. |release-badge| image:: https://img.shields.io/github/v/release/owent/libcopp\n               :alt: Release\n               :target: https://github.com/owent/libcopp/releases\n\n.. |code-size-badge| image:: https://img.shields.io/github/languages/code-size/owent/libcopp\n                     :alt: Code size\n                     :target: https://github.com/owent/libcopp\n\n.. |repo-size-badge| image:: https://img.shields.io/github/repo-size/owent/libcopp\n                     :alt: Repo size\n                     :target: https://github.com/owent/libcopp\n\n.. |forks-badge| image:: https://img.shields.io/github/forks/owent/libcopp?style=social\n                  :alt: Forks\n                  :target: https://github.com/owent/libcopp\n\n.. |stars-badge| image:: https://img.shields.io/github/stars/owent/libcopp?style=social\n                 :alt: Stars\n                 :target: https://github.com/owent/libcopp\n\n.. |ci-badge|  image:: https://github.com/owent/libcopp/actions/workflows/main.yml/badge.svg\n               :alt: CI build status\n               :target: https://github.com/owent/libcopp/actions/workflows/main.yml\n\n.. |codecov-badge|  image:: https://codecov.io/gh/owent/libcopp/branch/v2/graph/badge.svg\n                    :alt: Coveralls coverage\n                    :target: https://codecov.io/gh/owent/libcopp\n\n|release-badge| |code-size-badge| |repo-size-badge| |ci-badge| |codecov-badge| |forks-badge| |stars-badge|\n\nCI Job Matrix\n----------------\n\n+---------------+--------------------+-----------------------+\n| Target System | Toolchain          | Note                  |\n+===============+====================+=======================+\n| Linux         | GCC                | Static linking        |\n+---------------+--------------------+-----------------------+\n| Linux         | GCC                | Dynamic linking       |\n+---------------+--------------------+-----------------------+\n| Linux         | GCC-latest         |                       |\n+---------------+--------------------+-----------------------+\n| Linux         | GCC-latest         | No Exception          |\n+---------------+--------------------+-----------------------+\n| Linux         | GCC-latest         | Thread Unsafe         |\n+---------------+--------------------+-----------------------+\n| Linux         | GCC 4.8            | Legacy                |\n+---------------+--------------------+-----------------------+\n| Linux         | Clang-latest       | With libc++           |\n+---------------+--------------------+-----------------------+\n| MinGW64       | GCC                | Dynamic linking       |\n+---------------+--------------------+-----------------------+\n| Windows       | Visual Studio 2019 | Static linking        |\n+---------------+--------------------+-----------------------+\n| Windows       | Visual Studio 2019 | Dynamic linking       |\n+---------------+--------------------+-----------------------+\n| Windows       | Visual Studio 2017 | Legacy,Static linking |\n+---------------+--------------------+-----------------------+\n| macOS         | AppleClang         | With libc++           |\n+---------------+--------------------+-----------------------+\n\nLICENSE\n------------\n\nLicense under the `MIT LICENSE`_\n\nDocument\n------------\n\nDocuments can be found at https://libcopp.atframe.work , API references canbe found at https://libcopp.atframe.work/doxygen/html/ .(Generated by sphinx and doxygen with `docs/sphinx`_ and `docs/libcopp.doxyfile.in`_).\n\n\nUPGRADE FROM 1.3.X-1.4.X to 2.X\n------------------------------------\n\n+ Add ``using value_type = int;`` into ``T`` when using ``cotask::task\u003cT\u003e``.\n+ Rename ``stack_allocator_t`` to ``stack_allocator_type`` in ``T`` when using ``cotask::task\u003cT\u003e``.\n+ Rename ``coroutine_t`` to ``coroutine_type`` in ``T`` when using ``cotask::task\u003cT\u003e``.\n+ Rename ``libcopp::util::*`` to ``copp::util::``.\n+ We are not allowed to use ``libcopp::memory::intrusive_ptr\u003ccotask::impl::task_impl\u003e`` now, please use ``cotask::task\u003cT\u003e::ptr_type`` instead.\n\nUPGRADE FROM 1.2.X to 1.3.X-1.4.X\n------------------------------------\n\n+ Rename ``cotask::task::await`` into ``cotask::task::await_task``\n+ Replace ``cotask::task\u003cTCO_MACRO, TTASK_MACRO\u003e`` with ``cotask::task\u003cTCO_MACRO\u003e`` , we don't allow to custom id allocator now.\n+ Replace ``cotask::core::standard_int_id_allocator\u003cuint64_t\u003e`` with ``copp::util::uint64_id_allocator`` , we don't allow to custom id allocator now.\n+ Require gcc 4.8+, MSVC 15+(Visual Studio 2017)\u003e)\n+ Require `cmake`_ 3.12.0 or upper\n\nINSTALL\n------------\n\n| libcopp use `cmake`_ to generate makefile and switch build tools.\n\nPrerequisites\n^^^^^^^^^^^^^^^^\n\n* **[required]** GCC or Clang or MSVC or clang-cl support ISO C++ 11 and upper\n* **[required]** `cmake`_ 3.16.0 and upper\n* **[optional]** `gtest`_ 1.6.0 and upper (Better unit test supported)\n* **[optional]** `Boost.Test`_ (Boost.Test supported)\n\nUnix\n^^^^^^^^^^^^^^^^\n\n* **[required]** ``ar, as, ld`` (`binutils`_) or `llvm`_\n* **[optional]** if using `gtest`_ , pthread is required.\n\nWindows\n^^^^^^^^^^^^^^^^\n\n* **[required]** masm (in MSVC)\n* **[optional]** if using `gtest`_, pthread is required.\n\nInstall with vcpkg\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n1. Clone and setup `vcpkg`_ (See more detail on https://github.com/Microsoft/vcpkg)\n    .. code-block:: shell\n\n        git clone https://github.com/Microsoft/vcpkg.git\n        cd vcpkg\n        PS\u003e bootstrap-vcpkg.bootstrap\n        Linux:~/$ ./bootstrap-vcpkg.sh\n\n2. Install libcopp\n    .. code-block:: shell\n\n        PS\u003e .\\vcpkg install libcopp [--triplet x64-windows-static/x64-windows/x64-windows-static-md and etc...]\n        Linux:~/$ ./vcpkg install libcopp\n\n3. See :ref:`using with cmake \u003cusage-using with-cmake\u003e` for cmake below.\n\nCustom Build\n^^^^^^^^^^^^^^^^\n\n1. Clone and make a build directory\n    .. code-block:: shell\n\n        git clone --single-branch --depth=1 -b master https://github.com/owent/libcopp.git \n        mkdir libcopp/build \u0026\u0026 cd libcopp/build\n\n2. Run cmake command\n    .. code-block:: shell\n\n        # cmake \u003clibcopp dir\u003e [options...]\n        cmake .. -DPROJECT_ENABLE_UNITTEST=YES -DPROJECT_ENABLE_SAMPLE=YES\n\n3. Make libcopp\n    .. code-block:: shell\n\n        cmake --build . --config RelWithDebInfo # or make [options] when using Makefile\n\n4. Run ``test/sample/benchmark`` *[optional]*\n    .. code-block:: shell\n\n        # Run test =\u003e Required: PROJECT_ENABLE_UNITTEST=YES\n        ctest -VV . -C RelWithDebInfo -L libcopp.unit_test\n        # Run sample =\u003e Required: PROJECT_ENABLE_SAMPLE=YES\n        ctest -VV . -C RelWithDebInfo -L libcopp.sample\n        # Run benchmark =\u003e Required: PROJECT_ENABLE_SAMPLE=YES\n        ctest -VV . -C RelWithDebInfo -L libcopp.benchmark\n\n5. Install *[optional]*\n    .. code-block:: shell\n\n        cmake --build . --config RelWithDebInfo --target install # or make install when using Makefile\n\n6. Then just include and link ``libcopp.*/libcotask.*``, or see :ref:`using with cmake \u003cusage-using with-cmake\u003e` for cmake below.\n\nCMake Options\n----------------\n\nOptions can be cmake options. such as set compile toolchains, source directory or options of libcopp that control build actions. libcopp options are listed below:\n\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| Option                                   | Description                                                                                                                  |\n+==========================================+==============================================================================================================================+\n| BUILD_SHARED_LIBS=YES|NO                 | [default=NO] Build dynamic library.                                                                                          |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| LIBCOPP_ENABLE_SEGMENTED_STACKS=YES|NO   | [default=NO] Enable split stack supported context.(it's only availabe in linux and gcc 4.7.0 or upper)                       |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| LIBCOPP_ENABLE_VALGRIND=YES|NO           | [default=YES] Enable valgrind supported context.                                                                             |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| PROJECT_ENABLE_UNITTEST=YES|NO           | [default=NO] Build unit test.                                                                                                |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| PROJECT_ENABLE_SAMPLE=YES|NO             | [default=NO] Build samples.                                                                                                  |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| LIBCOPP_ENABLE_MULTI_THREAD=YES|NO       | [default=YES] Enable multi-thread support.                                                                                   |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| LIBCOTASK_ENABLE=YES|NO                  | [default=YES] Enable build libcotask.                                                                                        |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| LIBCOPP_FCONTEXT_USE_TSX=YES|NO          | [default=YES] Enable `Intel Transactional Synchronisation Extensions (TSX) \u003chttps://software.intel.com/en-us/node/695149\u003e`_. |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| LIBCOPP_MACRO_TLS_STACK_PROTECTOR=YES|NO | [default=NO] Users need set LIBCOPP_MACRO_TLS_STACK_PROTECTOR=ON when compiling with ``-fstack-protector``.                  |\n|                                          | Because it changes the default context switching logic.                                                                      |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| GTEST_ROOT=[path]                        | set gtest library install prefix path                                                                                        |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n| BOOST_ROOT=[path]                        | set Boost.Test library install prefix path                                                                                   |\n+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+\n\nUSAGE\n------------\n\n.. _usage-using with-cmake:\n\nUsing with cmake\n^^^^^^^^^^^^^^^^\n\n1. Using ``set(Libcopp_ROOT \u003cwhere to find libcopp/INSTALL_PREFIX\u003e)``\n2. Just using `find_package(Libcopp) \u003chttps://cmake.org/cmake/help/latest/command/find_package.html\u003e`_ to use libcopp module.\n3. Example:(we assume the target name is stored in ``${CUSTOM_TARGET_NAME}``)\n\n.. code-block:: cmake\n\n    find_package(Libcopp CONFIG REQUIRED)\n    target_link_libraries(${CUSTOM_TARGET_NAME} libcopp::cotask)\n    # Or just using copp by target_link_libraries(${CUSTOM_TARGET_NAME} libcopp::copp)\n\nIf using MSVC and vcpkg, CRT must match the triplet of vcpkg, these codes below may be helpful:\n\n.. code-block:: cmake\n\n    if (MSVC AND VCPKG_TOOLCHAIN)\n        if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)\n            set(VCPKG_TARGET_TRIPLET \"$ENV{VCPKG_DEFAULT_TRIPLET}\" CACHE STRING \"\")\n        endif()\n        if (VCPKG_TARGET_TRIPLET MATCHES \"^.*windows-static$\")\n            set(CMAKE_MSVC_RUNTIME_LIBRARY \"MultiThreaded$\u003c$\u003cCONFIG:Debug\u003e:Debug\u003e\" CACHE STRING \"\")\n        else ()\n            set(CMAKE_MSVC_RUNTIME_LIBRARY \"MultiThreaded$\u003c$\u003cCONFIG:Debug\u003e:Debug\u003eDLL\" CACHE STRING \"\")\n        endif ()\n    endif ()\n\nSee more detail on https://github.com/Microsoft/vcpkg/tree/master/ports/libcopp .\n\nDirectly use headers and libraries\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nJust include headers and linking library file of your platform to use libcopp.\n\n.. code-block:: shell\n\n    LIBCOPP_PREFIX=\u003cWHERE TO INSTALL libcopp\u003e\n\n    # Example command for build sample with gcc 4.9 or upper on Linux\n    for source in sample_readme_*.cpp; do\n        g++ -std=c++14 -O2 -g -ggdb -Wall -Werror -fPIC -rdynamic -fdiagnostics-color=auto -Wno-unused-local-typedefs \\\n            -I$LIBCOPP_PREFIX/include -L$LIBCOPP_PREFIX/lib64 -lcopp -lcotask $source -o $source.exe;\n    done\n\n    # Example command for build sample with clang 3.9 or upper and libc++ on Linux\n    for source in sample_readme_*.cpp; do\n        clang++ -std=c++17 -stdlib=libc++ -O2 -g -ggdb -Wall -Werror -fPIC -rdynamic        \\\n            -I$LIBCOPP_PREFIX/include -L$LIBCOPP_PREFIX/lib64 -lcopp -lcotask -lc++ -lc++abi  \\\n            $source -o $source.exe;\n    done\n\n    # AppleClang on macOS just like those scripts upper.\n    # If you are using MinGW on Windows, it's better to add -static-libstdc++ -static-libgcc to \n    #     use static linking and other scripts are just like those on Linux.\n\n\n.. code-block:: shell\n\n    # Example command for build sample with MSVC 1914 or upper on Windows \u0026 powershell(Debug Mode /MDd)\n    foreach ($source in Get-ChildItem -File -Name .\\sample_readme_*.cpp) {\n        cl /nologo /MP /W4 /wd\"4100\" /wd\"4125\" /EHsc /std:c++17 /Zc:__cplusplus /O2 /MDd /I$LIBCOPP_PREFIX/include $LIBCOPP_PREFIX/lib64/copp.lib $LIBCOPP_PREFIX/lib64/cotask.lib $source\n    }\n\n\nGet Start \u0026 Example\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThere serveral samples to use ``copp::coroutine_context`` 、 ``copp::coroutine_context_fiber`` and ``cotask::task`` :\n\n1. Using coroutine context\n2. Using coroutine task\n3. Using coroutine task manager\n4. Using stack pool\n5. Using ``task::then`` or ``task::await_task``\n6. Using ``copp::callable_promise`` of c++20 coroutine\n7. Using ``copp::generator_future`` for c++20 coroutine\n8. Custom error (timeout for example) when using c++20 coroutine\n9. Let c++20 coroutine work with ``cotask::task``\n10. Using Windows fiber and ``SetUnhandledExceptionFilter`` on Windows with ``cotask::task``\n11. Using c++20 coroutine with channel receiver and sender\n12. Using stackful coroutine task with channel receiver and sender\n\nAll sample codes can be found on :ref:`EXAMPLES \u003cexamples_doc_anchor\u003e` and `sample \u003chttps://github.com/owent/libcopp/tree/v2/sample\u003e`_ .\n\nNOTICE\n------------\n\nSplit stack support: if in Linux and user gcc 4.7.0 or upper, add ``-DLIBCOPP_ENABLE_SEGMENTED_STACKS=YES`` to use split stack supported context.\n\nIt's recommanded to use stack pool instead of gcc splited stack.\n\nBENCHMARK\n------------\n\nPlease see CI output for latest benchmark report. Click to visit `Github Actions \u003chttps://github.com/owent/libcopp/actions\u003e`_ .\n\nFAQ\n------------\n\nQ: How to enable c++20 coroutine\n\n| ANS: Add ``/std:c++latest /await`` for MSVC 1932 and below or ``-std=c++20 -fcoroutines-ts -stdlib=libc++`` for clang 13 and below or ``-std=c++20 -fcoroutines`` for gcc 10.\n\nIf you can just use ``-std=c++20 -stdlib=libc++`` clang 14 or above, ``-astd=c++20`` for gcc 11 or above, and ``/std:c++latest`` for MSVC 1932 or above.\n\nQ: Will libcopp handle exception?\n\n| ANS: When using c++11 or above, libcopp will catch all unhandled exception and rethrow it after coroutine resumed.\n\nQ: Why ``SetUnhandledExceptionFilter`` can not catch the unhandled exception in a coroutine?\n\n| ANS: ``SetUnhandledExceptionFilter`` only works with **Windows Fiber**, please see `sample/sample_readme_11.cpp \u003chttps://github.com/owent/libcopp/blob/v2/sample/sample_readme_11.cpp\u003e`_ for details.\n\nFEEDBACK\n------------\n\nIf you has any question, please create a issue and provide the information of your environments. For example:\n\n+ **OS**: Windows 10 Pro 19041 *(This can be see after running ``msinfo32``)* / Manjaro(Arch) Linux Linux 5.4.39-1-MANJARO\n+ **Compiler**: Visual Studio 2019 C++ 16.5.5 with VS 2019 C++ v14.25 or MSVC 1925/ gcc 9.3.0\n+ **CMake Commands**: ``cmake .. -G \"Visual Studio 16 2019\" -A x64 -DLIBCOPP_FCONTEXT_USE_TSX=ON -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=%cd%/install-prefix`` / ``cmake .. -G Ninja -DLIBCOPP_FCONTEXT_USE_TSX=ON -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/opt/libcopp``\n+ **Compile Commands**: ``cmake --build . -j``\n+ **Related Environment Variables**: Please provide all the environment variables which will change the cmake toolchain, ``CC`` 、 ``CXX`` 、 ``AR`` and etc.\n\nCONSTRIBUTORS\n------------------------\n\n+ `owent \u003chttps://github.com/owent\u003e`_\n\nTHANKS TO\n------------\n\n+ `mutouyun \u003chttps://github.com/mutouyun\u003e`_\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowent%2Flibcopp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fowent%2Flibcopp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowent%2Flibcopp/lists"}