Plattformübergreifende Coroutine-Bibliothek in C ++.

| Zielsystem | Toolchain | Notiz |
|---|---|---|
| Linux | GCC | Statische Verknüpfung |
| Linux | GCC | Dynamische Verknüpfung |
| Linux | GCC-LATEST | |
| Linux | GCC-LATEST | Keine Ausnahme |
| Linux | GCC-LATEST | Faden unsicher |
| Linux | GCC 4.8 | Vermächtnis |
| Linux | Klang-latest | Mit libc ++ |
| Mingw64 | GCC | Dynamische Verknüpfung |
| Fenster | Visual Studio 2019 | Statische Verknüpfung |
| Fenster | Visual Studio 2019 | Dynamische Verknüpfung |
| Fenster | Visual Studio 2017 | Vermächtnis, statische Verknüpfung |
| macos | Appleclang | Mit libc ++ |
Lizenz unter der MIT -Lizenz
Dokumente finden Sie unter https://libcopp.atframe.work, API -Referenzen können unter https://libcopp.atframe.work/doxygen/html/ gefunden (generiert von Sphinx und Doxygen).
using value_type = int; in T bei Verwendung von cotask::task<T> .stack_allocator_t in stack_allocator_type in t in t in T wenn Sie cotask::task<T> verwenden.coroutine_t in t in t in coroutine_type in T wenn Sie cotask::task<T> verwenden.libcopp::util::* in copp::util:: .libcopp::util::intrusive_ptr<cotask::impl::task_impl> nun verwenden, bitte verwenden Sie stattdessen cotask::task<T>::ptr_type . cotask::task::await cotask::task::await_taskcotask::task<TCO_MACRO, TTASK_MACRO> Mit cotask::task<TCO_MACRO> erlauben wir jetzt nicht den benutzerdefinierten ID -Allocator.cotask::core::standard_int_id_allocator<uint64_t> Mit copp::util::uint64_id_allocator erlauben wir jetzt nicht den benutzerdefinierten ID -Allocator.ar, as, ld (binutils) oder llvmgit clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
PS > bootstrap-vcpkg.bootstrap
Linux: ~ /$ ./bootstrap-vcpkg.shPS > . v cpkg install libcopp [--triplet x64-windows-static/x64-windows/x64-windows-static-md and etc...]
Linux: ~ /$ ./vcpkg install libcoppSiehe : Ref: `Verwenden mit CMake <Verwendung mit CMake>` Für CMake unten.
git clone --single-branch --depth=1 -b master https://github.com/owent/libcopp.git
mkdir libcopp/build && cd libcopp/build # cmake <libcopp dir> [options...]
cmake .. -DPROJECT_ENABLE_UNITTEST=YES -DPROJECT_ENABLE_SAMPLE=YEScmake --build . --config RelWithDebInfo # or make [options] when using Makefiletest/sample/benchmark ausführen [optional] # Run test => Required: PROJECT_ENABLE_UNITTEST=YES
ctest -VV . -C RelWithDebInfo -L libcopp.unit_test
# Run sample => Required: PROJECT_ENABLE_SAMPLE=YES
ctest -VV . -C RelWithDebInfo -L libcopp.sample
# Run benchmark => Required: PROJECT_ENABLE_SAMPLE=YES
ctest -VV . -C RelWithDebInfo -L libcopp.benchmarkcmake --build . --config RelWithDebInfo --target install # or make install when using Makefile Dann einfach libcopp.*/libcotask.* einschließen und verlinken.
Optionen können CMake -Optionen sein. z. B. Kompilierungs -Toolchains, Quellverzeichnis oder Optionen von libcopp, die Build -Aktionen steuern. Libcopp -Optionen sind unten aufgeführt:
| Option | Beschreibung |
|---|---|
| Build_shared_libs = Ja | Nein | [default = no] Erstellen Sie die dynamische Bibliothek. |
| Libcopp_enable_segmented_stacks = yes | nein | [default = no] Aktivieren Sie den geteilten Stack unterstützten Kontext. (Es ist nur verfügbar unter Linux und GCC 4.7.0 oder obere) |
| Libcopp_enable_valgrind = yes | nein | [default = yes] Aktivieren Sie Valgrind unterstützt den Kontext. |
| Project_enable_unittest = yes | nein | [Standard = Nein] Einheitstest erstellen. |
| Project_enable_sample = yes | nein | [default = no] Build -Proben. |
| Libcopp_lock_disable_this_mt = yes | nein | [default = no] Deaktivieren Sie die Unterstützung von Multi-Thread für copp::this_coroutine und cotask::this_task . |
| Libcopp_disable_atomic_lock = yes | nein | [default = no] Deaktivieren Sie Multi-Thread-Unterstützung. |
| Libcotask_enable = yes | nein | [default = yes] aktivieren bauen libcotask. |
| Libcopp_fcontext_use_tsx = yes | nein | [default = yes] Aktivieren Sie die Intel Transactional -Synchronisationserweiterungen (TSX). |
| Libcopp_macro_tls_stack_protector = yes | nein | [default = no] Benutzer müssen libcopp_macro_tls_stack_protector = on Beim Kompilieren mit -fstack-protector einstellen. Da es die Standard -Kontext -Switching -Logik ändert. |
| GTEST_ROOT = [PATH] | Legen Sie die GTEST -Bibliothek fest |
| Boost_root = [Path] | setzen |
set(Libcopp_ROOT <where to find libcopp/INSTALL_PREFIX>)${CUSTOM_TARGET_NAME} gespeichert ist) find_package (Libcopp CONFIG REQUIRED)
target_link_libraries ( ${CUSTOM_TARGET_NAME} libcopp::cotask)
# Or just using copp by target_link_libraries(${CUSTOM_TARGET_NAME} libcopp::copp)Bei Verwendung von MSVC und VCPKG muss CRT mit dem Triplett von VCPKG übereinstimmen, können diese folgenden Codes hilfreich sein:
if ( MSVC AND VCPKG_TOOLCHAIN)
if ( DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set (VCPKG_TARGET_TRIPLET " $ENV{VCPKG_DEFAULT_TRIPLET} " CACHE STRING "" )
endif ()
if (VCPKG_TARGET_TRIPLET MATCHES "^.*windows-static$" )
set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "" )
else ()
set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" CACHE STRING "" )
endif ()
endif ()Weitere Details finden Sie unter https://github.com/microsoft/vcpkg/tree/master/ports/libcopp.
Fügen Sie einfach Header und Verknüpfung der Bibliotheksdatei Ihrer Plattform zur Verwendung libcopp ein.
LIBCOPP_PREFIX= < WHERE TO INSTALL libcopp >
# Example command for build sample with gcc 4.9 or upper on Linux
for source in sample_readme_ * .cpp ; do
g++ -std=c++14 -O2 -g -ggdb -Wall -Werror -fPIC -rdynamic -fdiagnostics-color=auto -Wno-unused-local-typedefs
-I $LIBCOPP_PREFIX /include -L $LIBCOPP_PREFIX /lib64 -lcopp -lcotask $source -o $source .exe ;
done
# Example command for build sample with clang 3.9 or upper and libc++ on Linux
for source in sample_readme_ * .cpp ; do
clang++ -std=c++17 -stdlib=libc++ -O2 -g -ggdb -Wall -Werror -fPIC -rdynamic
-I $LIBCOPP_PREFIX /include -L $LIBCOPP_PREFIX /lib64 -lcopp -lcotask -lc++ -lc++abi
$source -o $source .exe ;
done
# AppleClang on macOS just like those scripts upper.
# If you are using MinGW on Windows, it's better to add -static-libstdc++ -static-libgcc to
# use static linking and other scripts are just like those on Linux. # Example command for build sample with MSVC 1914 or upper on Windows & powershell(Debug Mode /MDd)
foreach ( $source in Get-ChildItem -File -Name . s ample_readme_ * .cpp) {
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
} Es gibt Servermustern für copp::coroutine_context 、 copp::coroutine_context_fiber und cotask::task :
task::then oder task::await_taskcopp::callable_promise VON C ++ 20 COROUTINEcopp::generator_future für C ++ 20 Coroutinecotask::task arbeitenSetUnhandledExceptionFilter unter Windows mit cotask::taskAlle Beispielcodes finden Sie unter : Ref: `Beispiele <Beispiele_Doc_anchor>` und Beispiel.
Unterstützung von Split Stack: Wenn Sie in Linux und Benutzer GCC 4.7.0 oder obere, add -DLIBCOPP_ENABLE_SEGMENTED_STACKS=YES um einen geteilten Stapelkontext zu verwenden.
Es ist empfohlen, Stack Pool anstelle von GCC Splited Stack zu verwenden.
Bitte beachten Sie die CI -Ausgabe für den neuesten Benchmark -Bericht. Klicken Sie hier, um GitHub -Aktionen zu besuchen.
F: So aktivieren Sie C ++ 20 Coroutine
/std:c++latest /await für MSVC 1932 und unter oder -std=c++20 -fcoroutines-ts -stdlib=libc++ für Klang 13 und unten oder -std=c++20 -fcoroutines für GCC 10. Wenn Sie nur -std=c++20 -stdlib=libc++ clang 14 oder höher, -astd=c++20 für GCC 11 oder höher und /std:c++latest für MSVC 1932 oder höher.
F: Wird Libcopp eine Ausnahme ausführen?
F: Warum kann SetUnhandledExceptionFilter die unberechtigte Ausnahme in einer Coroutine nicht fangen?
SetUnhandledExceptionFilter funktioniert nur mit Windows -Faser . Weitere Informationen finden Sie in Sample/Sample_Readme_11.cpp. Wenn Sie Fragen haben, erstellen Sie bitte ein Problem und geben Sie die Informationen Ihrer Umgebungen an. Zum Beispiel:
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/libcoppcmake --build . -jCC 、 CXX 、 AR und E. usw. ändern.