Perpustakaan Cross-Platform Coroutine di C ++.

| Sistem target | Toolchain | Catatan |
|---|---|---|
| Linux | GCC | Tautan statis |
| Linux | GCC | Tautan dinamis |
| Linux | GCC-Latest | |
| Linux | GCC-Latest | Tidak terkecuali |
| Linux | GCC-Latest | Utas tidak aman |
| Linux | GCC 4.8 | Warisan |
| Linux | Clang-sorot | Dengan libc ++ |
| Mingw64 | GCC | Tautan dinamis |
| Windows | Visual Studio 2019 | Tautan statis |
| Windows | Visual Studio 2019 | Tautan dinamis |
| Windows | Visual Studio 2017 | Warisan, tautan statis |
| MacOS | Appleclang | Dengan libc ++ |
Lisensi Di Bawah Lisensi MIT
Dokumen dapat ditemukan di https://libcopp.atframe.work, API referensi dapat ditemukan di https://libcopp.atframe.work/doxygen/html/. (Dihasilkan oleh sphinx dan doxygen dengan docs/sphinx dan docs/libcopp.dox.dox.
using value_type = int; ke T saat menggunakan cotask::task<T> .stack_allocator_t menjadi stack_allocator_type di T saat menggunakan cotask::task<T> .coroutine_t ke coroutine_type di T saat menggunakan cotask::task<T> .libcopp::util::* ke copp::util:: .libcopp::util::intrusive_ptr<cotask::impl::task_impl> sekarang, silakan gunakan cotask::task<T>::ptr_type sebagai gantinya. cotask::task::await ke cotask::task::await_taskcotask::task<TCO_MACRO, TTASK_MACRO> dengan cotask::task<TCO_MACRO> , kami tidak mengizinkan untuk alokasi ID khusus sekarang.cotask::core::standard_int_id_allocator<uint64_t> dengan copp::util::uint64_id_allocator , kami tidak mengizinkan alokasi ID khusus sekarang.ar, as, ld (binutils) atau 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 libcoppLihat : Ref: `Menggunakan dengan cmake <penggunaan dengan cmake>` untuk cmake di bawah ini.
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 [Opsional] # 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 Kemudian cukup sertakan dan tautkan libcopp.*/libcotask.* , Atau lihat : ref: `menggunakan dengan cmake <usage-using with-cmake>` untuk cmake di bawah ini.
Opsi bisa menjadi opsi CMake. seperti set toolchains compile, direktori sumber atau opsi libcopp yang mengontrol tindakan pembuatan. Opsi libcopp tercantum di bawah ini:
| Pilihan | Keterangan |
|---|---|
| Build_shared_libs = ya | tidak | [default = tidak] Bangun Pustaka Dinamis. |
| Libcopp_enable_segmented_stacks = ya | tidak | [default = no] Aktifkan konteks yang didukung tumpukan split. (Hanya tersedia di Linux dan GCC 4.7.0 atau atas) |
| Libcopp_enable_valgrind = ya | tidak | [default = ya] Aktifkan konteks yang didukung Valgrind. |
| Project_enable_unittest = ya | tidak | [default = tidak] membangun tes unit. |
| Project_enable_sample = ya | tidak | [default = tidak] membangun sampel. |
| Libcopp_lock_disable_this_mt = ya | tidak | [default = tidak] Nonaktifkan dukungan multi-thread untuk copp::this_coroutine dan cotask::this_task . |
| Libcopp_disable_atomic_lock = ya | tidak | [default = no] Nonaktifkan dukungan multi-thread. |
| Libcotask_enable = ya | tidak | [default = ya] Aktifkan build libcotask. |
| Libcopp_fcontext_use_tsx = ya | tidak | [default = ya] Aktifkan ekstensi sinkronisasi transaksional Intel (TSX). |
| Libcopp_macro_tls_stack_protector = ya | tidak | [default = no] Pengguna perlu mengatur libcopp_macro_tls_stack_protector = on saat menyusun dengan -fstack-protector . Karena itu mengubah logika switching konteks default. |
| Gtest_root = [path] | Atur Jalur Prefix Instal Perpustakaan Gtest |
| Boost_root = [path] | atur boost.test pustaka instal jejak awalan |
set(Libcopp_ROOT <where to find libcopp/INSTALL_PREFIX>)${CUSTOM_TARGET_NAME} ) 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)Jika menggunakan MSVC dan VCPKG, CRT harus mencocokkan triplet VCPKG, kode -kode di bawah ini mungkin membantu:
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 ()Lihat detail lebih lanjut tentang https://github.com/microsoft/vcpkg/tree/master/ports/libcopp.
Cukup sertakan header dan menautkan file pustaka platform Anda untuk menggunakan libcopp.
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
} Ada sampel serveral untuk menggunakan copp::coroutine_context 、 copp::coroutine_context_fiber dan cotask::task :
task::then atau task::await_taskcopp::callable_promise dari C ++ 20 Coroutinecopp::generator_future untuk C ++ 20 Coroutinecotask::taskSetUnhandledExceptionFilter di Windows dengan cotask::taskSemua kode sampel dapat ditemukan di : REF: `Contoh <Contoh_Doc_anchor>` dan sampel.
Dukungan tumpukan split: Jika di Linux dan pengguna GCC 4.7.0 atau atas, tambahkan -DLIBCOPP_ENABLE_SEGMENTED_STACKS=YES untuk menggunakan konteks yang didukung tumpukan split.
Direkomendasikan untuk menggunakan stack pool, bukan tumpukan terpisah GCC.
Silakan lihat output CI untuk laporan benchmark terbaru. Klik untuk mengunjungi tindakan GitHub.
T: Cara Mengaktifkan C ++ 20 Coroutine
/std:c++latest /await untuk MSVC 1932 dan di bawah atau -std=c++20 -fcoroutines-ts -stdlib=libc++ untuk klang 13 dan di bawah atau -std=c++20 -fcoroutines untuk GCC 10. Jika Anda bisa menggunakan -std=c++20 -stdlib=libc++ clang 14 atau lebih, -astd=c++20 untuk gcc 11 atau lebih, dan /std:c++latest untuk msvc 1932 atau lebih.
T: Akankah libcopp menangani pengecualian?
T: Mengapa SetUnhandledExceptionFilter tidak dapat menangkap pengecualian yang tidak ditangani dalam coroutine?
SetUnhandledExceptionFilter hanya berfungsi dengan Windows Fiber , silakan lihat sampel/sample_readme_11.cpp untuk detailnya. Jika Anda memiliki pertanyaan, silakan buat masalah dan berikan informasi dari lingkungan Anda. Misalnya:
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 dan dll.